1 // 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.
5 #include "chrome/browser/ui/browser_command_controller.h"
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/defaults.h"
13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_util.h"
15 #include "chrome/browser/lifetime/application_lifetime.h"
16 #include "chrome/browser/prefs/incognito_mode_prefs.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "chrome/browser/sessions/tab_restore_service.h"
20 #include "chrome/browser/sessions/tab_restore_service_factory.h"
21 #include "chrome/browser/shell_integration.h"
22 #include "chrome/browser/signin/signin_promo.h"
23 #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"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
32 #include "chrome/browser/ui/webui/inspect_ui.h"
33 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/content_restriction.h"
35 #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"
40 #include "content/public/browser/user_metrics.h"
41 #include "content/public/browser/web_contents.h"
42 #include "content/public/browser/web_contents_observer.h"
43 #include "content/public/common/url_constants.h"
44 #include "extensions/browser/extension_system.h"
45 #include "ui/events/keycodes/keyboard_codes.h"
47 #if defined(OS_MACOSX)
48 #include "chrome/browser/ui/browser_commands_mac.h"
52 #include "base/win/metro.h"
53 #include "base/win/windows_version.h"
54 #include "chrome/browser/ui/apps/apps_metro_handler_win.h"
55 #include "content/public/browser/gpu_data_manager.h"
59 #include "ash/accelerators/accelerator_commands.h"
60 #include "chrome/browser/ui/ash/ash_util.h"
63 #if defined(OS_CHROMEOS)
64 #include "ash/multi_profile_uma.h"
65 #include "ash/session/session_state_delegate.h"
66 #include "ash/shell.h"
67 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
68 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
69 #include "chrome/browser/ui/browser_commands_chromeos.h"
72 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
73 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
76 using content::NavigationEntry
;
77 using content::NavigationController
;
78 using content::WebContents
;
83 // Not in fullscreen mode.
84 WINDOW_STATE_NOT_FULLSCREEN
,
86 // Fullscreen mode, occupying the whole screen.
87 WINDOW_STATE_FULLSCREEN
,
89 // Fullscreen mode for metro snap, occupying the full height and 20% of
91 WINDOW_STATE_METRO_SNAP
,
94 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
95 bool HasInternalURL(const NavigationEntry
* entry
) {
99 // Check the |virtual_url()| first. This catches regular chrome:// URLs
100 // including URLs that were rewritten (such as chrome://bookmarks).
101 if (entry
->GetVirtualURL().SchemeIs(content::kChromeUIScheme
))
104 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
105 // view-source: of a chrome:// URL.
106 if (entry
->GetVirtualURL().SchemeIs(content::kViewSourceScheme
))
107 return entry
->GetURL().SchemeIs(content::kChromeUIScheme
);
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.
122 // Note: this class deletes itself.
123 class SwitchToMetroUIHandler
124 : public ShellIntegration::DefaultWebClientObserver
{
126 SwitchToMetroUIHandler()
127 : default_browser_worker_(
128 new ShellIntegration::DefaultBrowserWorker(this)),
130 default_browser_worker_
->StartCheckIsDefault();
133 virtual ~SwitchToMetroUIHandler() {
134 default_browser_worker_
->ObserverDestroyed();
138 virtual void SetDefaultWebClientUIState(
139 ShellIntegration::DefaultWebClientUIState state
) override
{
141 case ShellIntegration::STATE_PROCESSING
:
143 case ShellIntegration::STATE_UNKNOWN
:
145 case ShellIntegration::STATE_IS_DEFAULT
:
146 chrome::AttemptRestartToMetroMode();
148 case ShellIntegration::STATE_NOT_DEFAULT
:
150 default_browser_worker_
->StartSetAsDefault();
160 virtual void OnSetAsDefaultConcluded(bool success
) override
{
165 first_check_
= false;
166 default_browser_worker_
->StartCheckIsDefault();
169 virtual bool IsInteractiveSetDefaultPermitted() override
{
173 scoped_refptr
<ShellIntegration::DefaultBrowserWorker
> default_browser_worker_
;
176 DISALLOW_COPY_AND_ASSIGN(SwitchToMetroUIHandler
);
178 #endif // defined(OS_WIN)
184 ///////////////////////////////////////////////////////////////////////////////
185 // BrowserCommandController, public:
187 BrowserCommandController::BrowserCommandController(Browser
* browser
)
189 command_updater_(this),
190 block_command_execution_(false),
191 last_blocked_command_id_(-1),
192 last_blocked_command_disposition_(CURRENT_TAB
) {
193 browser_
->tab_strip_model()->AddObserver(this);
194 PrefService
* local_state
= g_browser_process
->local_state();
196 local_pref_registrar_
.Init(local_state
);
197 local_pref_registrar_
.Add(
198 prefs::kAllowFileSelectionDialogs
,
200 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs
,
201 base::Unretained(this)));
204 profile_pref_registrar_
.Init(profile()->GetPrefs());
205 profile_pref_registrar_
.Add(
206 prefs::kDevToolsDisabled
,
207 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools
,
208 base::Unretained(this)));
209 profile_pref_registrar_
.Add(
210 bookmarks::prefs::kEditBookmarksEnabled
,
211 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing
,
212 base::Unretained(this)));
213 profile_pref_registrar_
.Add(
214 bookmarks::prefs::kShowBookmarkBar
,
215 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar
,
216 base::Unretained(this)));
217 profile_pref_registrar_
.Add(
218 prefs::kIncognitoModeAvailability
,
220 &BrowserCommandController::UpdateCommandsForIncognitoAvailability
,
221 base::Unretained(this)));
222 profile_pref_registrar_
.Add(
223 prefs::kPrintingEnabled
,
224 base::Bind(&BrowserCommandController::UpdatePrintingState
,
225 base::Unretained(this)));
226 #if !defined(OS_MACOSX)
227 profile_pref_registrar_
.Add(
228 prefs::kFullscreenAllowed
,
229 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode
,
230 base::Unretained(this)));
232 pref_signin_allowed_
.Init(
233 prefs::kSigninAllowed
,
234 profile()->GetOriginalProfile()->GetPrefs(),
235 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange
,
236 base::Unretained(this)));
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
);
248 BrowserCommandController::~BrowserCommandController() {
249 // TabRestoreService may have been shutdown by the time we get here. Don't
250 // trigger creating it.
251 TabRestoreService
* tab_restore_service
=
252 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
253 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);
260 bool BrowserCommandController::IsReservedCommandOrKey(
262 const content::NativeWebKeyboardEvent
& event
) {
263 // In Apps mode, no keys are reserved.
264 if (browser_
->is_app())
267 #if defined(OS_CHROMEOS)
268 // 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.
272 ui::KeyboardCode key_code
=
273 static_cast<ui::KeyboardCode
>(event
.windowsKeyCode
);
274 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
)) {
281 if (window()->IsFullscreen() && command_id
== IDC_FULLSCREEN
)
284 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
285 // If this key was registered by the user as a content editing hotkey, then
286 // it is not reserved.
287 ui::TextEditKeyBindingsDelegateAuraLinux
* delegate
=
288 ui::GetTextEditKeyBindingsDelegate();
289 if (delegate
&& event
.os_event
&& delegate
->MatchEvent(*event
.os_event
, NULL
))
293 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
||
301 command_id
== IDC_EXIT
;
304 void BrowserCommandController::SetBlockCommandExecution(bool block
) {
305 block_command_execution_
= block
;
307 last_blocked_command_id_
= -1;
308 last_blocked_command_disposition_
= CURRENT_TAB
;
312 int BrowserCommandController::GetLastBlockedCommand(
313 WindowOpenDisposition
* disposition
) {
315 *disposition
= last_blocked_command_disposition_
;
316 return last_blocked_command_id_
;
319 void BrowserCommandController::TabStateChanged() {
320 UpdateCommandsForTabState();
323 void BrowserCommandController::ZoomStateChanged() {
324 UpdateCommandsForZoomState();
327 void BrowserCommandController::ContentRestrictionsChanged() {
328 UpdateCommandsForContentRestrictionState();
331 void BrowserCommandController::FullscreenStateChanged() {
332 UpdateCommandsForFullscreenMode();
335 void BrowserCommandController::PrintingStateChanged() {
336 UpdatePrintingState();
339 void BrowserCommandController::LoadingStateChanged(bool is_loading
,
341 UpdateReloadStopState(is_loading
, force
);
344 void BrowserCommandController::ExtensionStateChanged() {
345 // Extensions may disable the bookmark editing commands.
346 UpdateCommandsForBookmarkEditing();
349 ////////////////////////////////////////////////////////////////////////////////
350 // BrowserCommandController, CommandUpdaterDelegate implementation:
352 void BrowserCommandController::ExecuteCommandWithDisposition(
354 WindowOpenDisposition disposition
) {
355 // No commands are enabled if there is not yet any selected tab.
356 // TODO(pkasting): It seems like we should not need this, because either
357 // most/all commands should not have been enabled yet anyway or the ones that
358 // are enabled should be global, or safe themselves against having no selected
359 // tab. However, Ben says he tried removing this before and got lots of
360 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
361 // window construction. This probably could use closer examination someday.
362 if (browser_
->tab_strip_model()->active_index() == TabStripModel::kNoTab
)
365 DCHECK(command_updater_
.IsCommandEnabled(id
)) << "Invalid/disabled command "
368 // If command execution is blocked then just record the command and return.
369 if (block_command_execution_
) {
370 // We actually only allow no more than one blocked command, otherwise some
371 // commands maybe lost.
372 DCHECK_EQ(last_blocked_command_id_
, -1);
373 last_blocked_command_id_
= id
;
374 last_blocked_command_disposition_
= disposition
;
378 // The order of commands in this switch statement must match the function
379 // declaration order in browser.h!
381 // Navigation commands
383 GoBack(browser_
, disposition
);
386 GoForward(browser_
, disposition
);
389 Reload(browser_
, disposition
);
391 case IDC_RELOAD_CLEARING_CACHE
:
392 ClearCache(browser_
);
394 case IDC_RELOAD_IGNORING_CACHE
:
395 ReloadIgnoringCache(browser_
, disposition
);
398 Home(browser_
, disposition
);
400 case IDC_OPEN_CURRENT_URL
:
401 OpenCurrentURL(browser_
);
407 // Window management commands
411 case IDC_NEW_INCOGNITO_WINDOW
:
412 NewIncognitoWindow(browser_
);
414 case IDC_CLOSE_WINDOW
:
415 content::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
416 CloseWindow(browser_
);
422 content::RecordAction(base::UserMetricsAction("CloseTabByKey"));
425 case IDC_SELECT_NEXT_TAB
:
426 content::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
427 SelectNextTab(browser_
);
429 case IDC_SELECT_PREVIOUS_TAB
:
430 content::RecordAction(
431 base::UserMetricsAction("Accel_SelectPreviousTab"));
432 SelectPreviousTab(browser_
);
434 case IDC_MOVE_TAB_NEXT
:
435 MoveTabNext(browser_
);
437 case IDC_MOVE_TAB_PREVIOUS
:
438 MoveTabPrevious(browser_
);
440 case IDC_SELECT_TAB_0
:
441 case IDC_SELECT_TAB_1
:
442 case IDC_SELECT_TAB_2
:
443 case IDC_SELECT_TAB_3
:
444 case IDC_SELECT_TAB_4
:
445 case IDC_SELECT_TAB_5
:
446 case IDC_SELECT_TAB_6
:
447 case IDC_SELECT_TAB_7
:
448 SelectNumberedTab(browser_
, id
- IDC_SELECT_TAB_0
);
450 case IDC_SELECT_LAST_TAB
:
451 SelectLastTab(browser_
);
453 case IDC_DUPLICATE_TAB
:
454 DuplicateTab(browser_
);
456 case IDC_RESTORE_TAB
:
457 RestoreTab(browser_
);
459 case IDC_SHOW_AS_TAB
:
460 ConvertPopupToTabbedBrowser(browser_
);
463 #if defined(OS_MACOSX)
464 chrome::ToggleFullscreenWithToolbarOrFallback(browser_
);
466 chrome::ToggleFullscreenMode(browser_
);
470 #if defined(OS_CHROMEOS)
471 case IDC_VISIT_DESKTOP_OF_LRU_USER_2
:
472 case IDC_VISIT_DESKTOP_OF_LRU_USER_3
:
473 ExecuteVisitDesktopCommand(id
, browser_
->window()->GetNativeWindow());
477 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
478 case IDC_USE_SYSTEM_TITLE_BAR
: {
479 PrefService
* prefs
= browser_
->profile()->GetPrefs();
480 prefs
->SetBoolean(prefs::kUseCustomChromeFrame
,
481 !prefs
->GetBoolean(prefs::kUseCustomChromeFrame
));
487 // Windows 8 specific commands.
488 case IDC_METRO_SNAP_ENABLE
:
489 browser_
->SetMetroSnapMode(true);
491 case IDC_METRO_SNAP_DISABLE
:
492 browser_
->SetMetroSnapMode(false);
494 case IDC_WIN_DESKTOP_RESTART
:
495 if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id
))
498 chrome::AttemptRestartToDesktopMode();
499 if (base::win::GetVersion() >= base::win::VERSION_WIN8
) {
500 content::RecordAction(base::UserMetricsAction("Win8DesktopRestart"));
502 content::RecordAction(base::UserMetricsAction("Win7DesktopRestart"));
505 case IDC_WIN8_METRO_RESTART
:
506 case IDC_WIN_CHROMEOS_RESTART
:
507 if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id
))
509 if (base::win::GetVersion() >= base::win::VERSION_WIN8
) {
510 // SwitchToMetroUIHandler deletes itself.
511 new SwitchToMetroUIHandler
;
512 content::RecordAction(base::UserMetricsAction("Win8MetroRestart"));
514 content::RecordAction(base::UserMetricsAction("Win7ASHRestart"));
515 chrome::AttemptRestartToMetroMode();
518 case IDC_PIN_TO_START_SCREEN
:
519 TogglePagePinnedToStartScreen(browser_
);
523 #if defined(OS_MACOSX)
524 case IDC_PRESENTATION_MODE
:
525 chrome::ToggleFullscreenMode(browser_
);
532 // Page-related commands
536 case IDC_BOOKMARK_PAGE
:
537 BookmarkCurrentPageAllowingExtensionOverrides(browser_
);
539 case IDC_BOOKMARK_ALL_TABS
:
540 BookmarkAllTabs(browser_
);
542 case IDC_VIEW_SOURCE
:
543 ViewSelectedSource(browser_
);
545 case IDC_EMAIL_PAGE_LOCATION
:
546 EmailPageLocation(browser_
);
551 #if defined(ENABLE_BASIC_PRINTING)
552 case IDC_BASIC_PRINT
:
553 content::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
554 BasicPrint(browser_
);
556 #endif // ENABLE_BASIC_PRINTING
557 case IDC_TRANSLATE_PAGE
:
560 case IDC_MANAGE_PASSWORDS_FOR_PAGE
:
561 ManagePasswordsForPage(browser_
);
564 // Page encoding commands
565 case IDC_ENCODING_AUTO_DETECT
:
566 browser_
->ToggleEncodingAutoDetect();
568 case IDC_ENCODING_UTF8
:
569 case IDC_ENCODING_UTF16LE
:
570 case IDC_ENCODING_WINDOWS1252
:
571 case IDC_ENCODING_GBK
:
572 case IDC_ENCODING_GB18030
:
573 case IDC_ENCODING_BIG5HKSCS
:
574 case IDC_ENCODING_BIG5
:
575 case IDC_ENCODING_KOREAN
:
576 case IDC_ENCODING_SHIFTJIS
:
577 case IDC_ENCODING_ISO2022JP
:
578 case IDC_ENCODING_EUCJP
:
579 case IDC_ENCODING_THAI
:
580 case IDC_ENCODING_ISO885915
:
581 case IDC_ENCODING_MACINTOSH
:
582 case IDC_ENCODING_ISO88592
:
583 case IDC_ENCODING_WINDOWS1250
:
584 case IDC_ENCODING_ISO88595
:
585 case IDC_ENCODING_WINDOWS1251
:
586 case IDC_ENCODING_KOI8R
:
587 case IDC_ENCODING_KOI8U
:
588 case IDC_ENCODING_ISO88597
:
589 case IDC_ENCODING_WINDOWS1253
:
590 case IDC_ENCODING_ISO88594
:
591 case IDC_ENCODING_ISO885913
:
592 case IDC_ENCODING_WINDOWS1257
:
593 case IDC_ENCODING_ISO88593
:
594 case IDC_ENCODING_ISO885910
:
595 case IDC_ENCODING_ISO885914
:
596 case IDC_ENCODING_ISO885916
:
597 case IDC_ENCODING_WINDOWS1254
:
598 case IDC_ENCODING_ISO88596
:
599 case IDC_ENCODING_WINDOWS1256
:
600 case IDC_ENCODING_ISO88598
:
601 case IDC_ENCODING_ISO88598I
:
602 case IDC_ENCODING_WINDOWS1255
:
603 case IDC_ENCODING_WINDOWS1258
:
604 browser_
->OverrideEncoding(id
);
607 // Clipboard commands
625 case IDC_FIND_PREVIOUS
:
626 FindPrevious(browser_
);
631 Zoom(browser_
, content::PAGE_ZOOM_IN
);
633 case IDC_ZOOM_NORMAL
:
634 Zoom(browser_
, content::PAGE_ZOOM_RESET
);
637 Zoom(browser_
, content::PAGE_ZOOM_OUT
);
640 // Focus various bits of UI
641 case IDC_FOCUS_TOOLBAR
:
642 content::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
643 FocusToolbar(browser_
);
645 case IDC_FOCUS_LOCATION
:
646 content::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
647 FocusLocationBar(browser_
);
649 case IDC_FOCUS_SEARCH
:
650 content::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
651 FocusSearch(browser_
);
653 case IDC_FOCUS_MENU_BAR
:
654 FocusAppMenu(browser_
);
656 case IDC_FOCUS_BOOKMARKS
:
657 content::RecordAction(
658 base::UserMetricsAction("Accel_Focus_Bookmarks"));
659 FocusBookmarksToolbar(browser_
);
661 case IDC_FOCUS_INFOBARS
:
662 FocusInfobars(browser_
);
664 case IDC_FOCUS_NEXT_PANE
:
665 FocusNextPane(browser_
);
667 case IDC_FOCUS_PREVIOUS_PANE
:
668 FocusPreviousPane(browser_
);
671 // Show various bits of UI
673 browser_
->OpenFile();
675 case IDC_CREATE_SHORTCUTS
:
676 CreateApplicationShortcuts(browser_
);
678 case IDC_CREATE_HOSTED_APP
:
679 CreateBookmarkAppFromCurrentWebContents(browser_
);
682 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::Show());
684 case IDC_DEV_TOOLS_CONSOLE
:
685 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::ShowConsole());
687 case IDC_DEV_TOOLS_DEVICES
:
688 InspectUI::InspectDevices(browser_
);
690 case IDC_DEV_TOOLS_INSPECT
:
691 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::Inspect());
693 case IDC_DEV_TOOLS_TOGGLE
:
694 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::Toggle());
696 case IDC_TASK_MANAGER
:
697 OpenTaskManager(browser_
);
699 #if defined(OS_CHROMEOS)
700 case IDC_TAKE_SCREENSHOT
:
704 #if defined(GOOGLE_CHROME_BUILD)
706 OpenFeedbackDialog(browser_
);
709 case IDC_SHOW_BOOKMARK_BAR
:
710 ToggleBookmarkBar(browser_
);
712 case IDC_PROFILING_ENABLED
:
716 case IDC_SHOW_BOOKMARK_MANAGER
:
717 ShowBookmarkManager(browser_
);
719 case IDC_SHOW_APP_MENU
:
720 content::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
721 ShowAppMenu(browser_
);
723 case IDC_SHOW_AVATAR_MENU
:
724 ShowAvatarMenu(browser_
);
726 case IDC_SHOW_HISTORY
:
727 ShowHistory(browser_
);
729 case IDC_SHOW_DOWNLOADS
:
730 ShowDownloads(browser_
);
732 case IDC_MANAGE_EXTENSIONS
:
733 ShowExtensions(browser_
, std::string());
736 ShowSettings(browser_
);
738 case IDC_EDIT_SEARCH_ENGINES
:
739 ShowSearchEngineSettings(browser_
);
741 case IDC_VIEW_PASSWORDS
:
742 ShowPasswordManager(browser_
);
744 case IDC_CLEAR_BROWSING_DATA
:
745 ShowClearBrowsingDataDialog(browser_
);
747 case IDC_IMPORT_SETTINGS
:
748 ShowImportDialog(browser_
);
750 case IDC_TOGGLE_REQUEST_TABLET_SITE
:
751 ToggleRequestTabletSite(browser_
);
754 ShowAboutChrome(browser_
);
756 case IDC_UPGRADE_DIALOG
:
757 OpenUpdateChromeDialog(browser_
);
759 case IDC_VIEW_INCOMPATIBILITIES
:
760 ShowConflicts(browser_
);
762 case IDC_HELP_PAGE_VIA_KEYBOARD
:
763 ShowHelp(browser_
, HELP_SOURCE_KEYBOARD
);
765 case IDC_HELP_PAGE_VIA_MENU
:
766 ShowHelp(browser_
, HELP_SOURCE_MENU
);
768 case IDC_SHOW_SIGNIN
:
769 ShowBrowserSigninOrSettings(browser_
, signin_metrics::SOURCE_MENU
);
771 case IDC_TOGGLE_SPEECH_INPUT
:
772 ToggleSpeechInput(browser_
);
774 case IDC_DISTILL_PAGE
:
775 DistillCurrentPage(browser_
);
777 #if defined(OS_CHROMEOS)
778 case IDC_TOUCH_HUD_PROJECTION_TOGGLE
:
779 ash::accelerators::ToggleTouchHudProjection();
784 LOG(WARNING
) << "Received Unimplemented Command: " << id
;
789 ////////////////////////////////////////////////////////////////////////////////
790 // BrowserCommandController, SigninPrefObserver implementation:
792 void BrowserCommandController::OnSigninAllowedPrefChange() {
793 // For unit tests, we don't have a window.
796 UpdateShowSyncState(IsShowingMainUI());
799 // BrowserCommandController, TabStripModelObserver implementation:
801 void BrowserCommandController::TabInsertedAt(WebContents
* contents
,
804 AddInterstitialObservers(contents
);
807 void BrowserCommandController::TabDetachedAt(WebContents
* contents
, int index
) {
808 RemoveInterstitialObservers(contents
);
811 void BrowserCommandController::TabReplacedAt(TabStripModel
* tab_strip_model
,
812 WebContents
* old_contents
,
813 WebContents
* new_contents
,
815 RemoveInterstitialObservers(old_contents
);
816 AddInterstitialObservers(new_contents
);
819 void BrowserCommandController::TabBlockedStateChanged(
820 content::WebContents
* contents
,
822 PrintingStateChanged();
823 FullscreenStateChanged();
824 UpdateCommandsForFind();
827 ////////////////////////////////////////////////////////////////////////////////
828 // BrowserCommandController, TabRestoreServiceObserver implementation:
830 void BrowserCommandController::TabRestoreServiceChanged(
831 TabRestoreService
* service
) {
832 UpdateTabRestoreCommandState();
835 void BrowserCommandController::TabRestoreServiceDestroyed(
836 TabRestoreService
* service
) {
837 service
->RemoveObserver(this);
840 void BrowserCommandController::TabRestoreServiceLoaded(
841 TabRestoreService
* service
) {
842 UpdateTabRestoreCommandState();
845 ////////////////////////////////////////////////////////////////////////////////
846 // BrowserCommandController, private:
848 class BrowserCommandController::InterstitialObserver
849 : public content::WebContentsObserver
{
851 InterstitialObserver(BrowserCommandController
* controller
,
852 content::WebContents
* web_contents
)
853 : WebContentsObserver(web_contents
),
854 controller_(controller
) {
857 void DidAttachInterstitialPage() override
{
858 controller_
->UpdateCommandsForTabState();
861 void DidDetachInterstitialPage() override
{
862 controller_
->UpdateCommandsForTabState();
866 BrowserCommandController
* controller_
;
868 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver
);
871 bool BrowserCommandController::IsShowingMainUI() {
872 bool should_hide_ui
= window() && window()->ShouldHideUIForFullscreen();
873 return browser_
->is_type_tabbed() && !should_hide_ui
;
876 void BrowserCommandController::InitCommandState() {
877 // All browser commands whose state isn't set automagically some other way
878 // (like Back & Forward with initial page load) must have their state
879 // initialized here, otherwise they will be forever disabled.
881 // Navigation commands
882 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, true);
883 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
, true);
884 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
, true);
886 // Window management commands
887 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_WINDOW
, true);
888 command_updater_
.UpdateCommandEnabled(IDC_NEW_TAB
, true);
889 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_TAB
, true);
890 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
, true);
891 UpdateTabRestoreCommandState();
892 #if defined(OS_WIN) && defined(USE_ASH)
893 if (browser_
->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH
)
894 command_updater_
.UpdateCommandEnabled(IDC_EXIT
, true);
896 command_updater_
.UpdateCommandEnabled(IDC_EXIT
, true);
898 command_updater_
.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE
, true);
900 command_updater_
.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW
, true);
902 #if defined(OS_CHROMEOS)
903 command_updater_
.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2
, true);
904 command_updater_
.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3
, true);
906 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
907 command_updater_
.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR
, true);
910 // Page-related commands
911 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
, true);
912 command_updater_
.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE
, true);
913 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT
, true);
914 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF8
, true);
915 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF16LE
, true);
916 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252
, true);
917 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GBK
, true);
918 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GB18030
, true);
919 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS
, true);
920 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5
, true);
921 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_THAI
, true);
922 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOREAN
, true);
923 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS
, true);
924 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP
, true);
925 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_EUCJP
, true);
926 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885915
, true);
927 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH
, true);
928 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88592
, true);
929 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250
, true);
930 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88595
, true);
931 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251
, true);
932 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8R
, true);
933 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8U
, true);
934 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88597
, true);
935 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253
, true);
936 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88594
, true);
937 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885913
, true);
938 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257
, true);
939 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88593
, true);
940 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885910
, true);
941 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885914
, true);
942 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885916
, true);
943 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254
, true);
944 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88596
, true);
945 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256
, true);
946 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598
, true);
947 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598I
, true);
948 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255
, true);
949 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258
, true);
952 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MENU
, true);
953 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_PLUS
, true);
954 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_NORMAL
, false);
955 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MINUS
, true);
957 // Show various bits of UI
958 const bool guest_session
= profile()->IsGuestSession();
959 const bool normal_window
= browser_
->is_type_tabbed();
960 UpdateOpenFileState(&command_updater_
);
961 command_updater_
.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS
, false);
962 UpdateCommandsForDevTools();
963 command_updater_
.UpdateCommandEnabled(IDC_TASK_MANAGER
, CanOpenTaskManager());
964 command_updater_
.UpdateCommandEnabled(IDC_SHOW_HISTORY
, !guest_session
);
965 command_updater_
.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS
, true);
966 command_updater_
.UpdateCommandEnabled(IDC_HELP_MENU
, true);
967 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD
, true);
968 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU
, true);
969 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARKS_MENU
, !guest_session
);
970 command_updater_
.UpdateCommandEnabled(IDC_RECENT_TABS_MENU
,
972 !profile()->IsOffTheRecord());
973 command_updater_
.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA
, normal_window
);
974 #if defined(OS_CHROMEOS)
975 command_updater_
.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT
, true);
976 command_updater_
.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE
, true);
978 // Chrome OS uses the system tray menu to handle multi-profiles.
979 if (normal_window
&& (guest_session
|| !profile()->IsOffTheRecord()))
980 command_updater_
.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU
, true);
983 UpdateShowSyncState(true);
985 // Navigation commands
986 command_updater_
.UpdateCommandEnabled(
989 (extensions::util::IsNewBookmarkAppsEnabled() && browser_
->is_app()));
991 // Window management commands
992 command_updater_
.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB
, normal_window
);
993 command_updater_
.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB
,
995 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT
, normal_window
);
996 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS
, normal_window
);
997 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_0
, normal_window
);
998 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_1
, normal_window
);
999 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_2
, normal_window
);
1000 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_3
, normal_window
);
1001 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_4
, normal_window
);
1002 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_5
, normal_window
);
1003 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_6
, normal_window
);
1004 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_7
, normal_window
);
1005 command_updater_
.UpdateCommandEnabled(IDC_SELECT_LAST_TAB
, normal_window
);
1007 bool metro
= browser_
->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH
;
1008 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE
, metro
);
1009 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE
, metro
);
1010 int restart_mode
= metro
? IDC_WIN_DESKTOP_RESTART
:
1011 (base::win::GetVersion() >= base::win::VERSION_WIN8
?
1012 IDC_WIN8_METRO_RESTART
: IDC_WIN_CHROMEOS_RESTART
);
1013 command_updater_
.UpdateCommandEnabled(restart_mode
, normal_window
);
1016 // These are always enabled; the menu determines their menu item visibility.
1017 command_updater_
.UpdateCommandEnabled(IDC_UPGRADE_DIALOG
, true);
1018 command_updater_
.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES
, true);
1020 // Toggle speech input
1021 command_updater_
.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT
, true);
1023 // Distill current page.
1024 command_updater_
.UpdateCommandEnabled(
1025 IDC_DISTILL_PAGE
, base::CommandLine::ForCurrentProcess()->HasSwitch(
1026 switches::kEnableDomDistiller
));
1028 // Initialize other commands whose state changes based on various conditions.
1029 UpdateCommandsForFullscreenMode();
1030 UpdateCommandsForContentRestrictionState();
1031 UpdateCommandsForBookmarkEditing();
1032 UpdateCommandsForIncognitoAvailability();
1036 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1037 CommandUpdater
* command_updater
,
1039 const bool guest_session
= profile
->IsGuestSession();
1040 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
1041 IncognitoModePrefs::Availability incognito_availability
=
1042 IncognitoModePrefs::GetAvailability(profile
->GetPrefs());
1043 command_updater
->UpdateCommandEnabled(
1045 incognito_availability
!= IncognitoModePrefs::FORCED
);
1046 command_updater
->UpdateCommandEnabled(
1047 IDC_NEW_INCOGNITO_WINDOW
,
1048 incognito_availability
!= IncognitoModePrefs::DISABLED
&& !guest_session
);
1050 const bool forced_incognito
=
1051 incognito_availability
== IncognitoModePrefs::FORCED
||
1052 guest_session
; // Guest always runs in Incognito mode.
1053 command_updater
->UpdateCommandEnabled(
1054 IDC_SHOW_BOOKMARK_MANAGER
,
1055 browser_defaults::bookmarks_enabled
&& !forced_incognito
);
1056 ExtensionService
* extension_service
=
1057 extensions::ExtensionSystem::Get(profile
)->extension_service();
1058 const bool enable_extensions
=
1059 extension_service
&& extension_service
->extensions_enabled();
1061 // Bookmark manager and settings page/subpages are forced to open in normal
1062 // mode. For this reason we disable these commands when incognito is forced.
1063 command_updater
->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS
,
1064 enable_extensions
&& !forced_incognito
);
1066 command_updater
->UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, !forced_incognito
);
1067 command_updater
->UpdateCommandEnabled(IDC_OPTIONS
,
1068 !forced_incognito
|| guest_session
);
1069 command_updater
->UpdateCommandEnabled(IDC_SHOW_SIGNIN
, !forced_incognito
);
1072 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
1073 UpdateSharedCommandsForIncognitoAvailability(&command_updater_
, profile());
1075 if (!IsShowingMainUI()) {
1076 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, false);
1077 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
, false);
1081 void BrowserCommandController::UpdateCommandsForTabState() {
1082 WebContents
* current_web_contents
=
1083 browser_
->tab_strip_model()->GetActiveWebContents();
1084 if (!current_web_contents
) // May be NULL during tab restore.
1087 // Navigation commands
1088 command_updater_
.UpdateCommandEnabled(IDC_BACK
, CanGoBack(browser_
));
1089 command_updater_
.UpdateCommandEnabled(IDC_FORWARD
, CanGoForward(browser_
));
1090 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, CanReload(browser_
));
1091 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
,
1092 CanReload(browser_
));
1093 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
,
1094 CanReload(browser_
));
1096 // Window management commands
1097 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
,
1098 !browser_
->is_app() && CanDuplicateTab(browser_
));
1100 // Page-related commands
1101 window()->SetStarredState(
1102 BookmarkTabHelper::FromWebContents(current_web_contents
)->is_starred());
1103 window()->ZoomChangedForActiveTab(false);
1104 command_updater_
.UpdateCommandEnabled(IDC_VIEW_SOURCE
,
1105 CanViewSource(browser_
));
1106 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
,
1107 CanEmailPageLocation(browser_
));
1108 if (browser_
->is_devtools())
1109 command_updater_
.UpdateCommandEnabled(IDC_OPEN_FILE
, false);
1111 // Changing the encoding is not possible on Chrome-internal webpages.
1112 NavigationController
& nc
= current_web_contents
->GetController();
1113 bool is_chrome_internal
= HasInternalURL(nc
.GetLastCommittedEntry()) ||
1114 current_web_contents
->ShowingInterstitialPage();
1115 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MENU
,
1116 !is_chrome_internal
&& current_web_contents
->IsSavable());
1118 // Show various bits of UI
1119 // TODO(pinkerton): Disable app-mode in the model until we implement it
1120 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
1121 #if !defined(OS_MACOSX)
1122 command_updater_
.UpdateCommandEnabled(
1123 IDC_CREATE_SHORTCUTS
,
1124 CanCreateApplicationShortcuts(browser_
));
1126 command_updater_
.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP
,
1127 CanCreateBookmarkApp(browser_
));
1129 command_updater_
.UpdateCommandEnabled(
1130 IDC_TOGGLE_REQUEST_TABLET_SITE
,
1131 CanRequestTabletSite(current_web_contents
));
1133 UpdateCommandsForContentRestrictionState();
1134 UpdateCommandsForBookmarkEditing();
1135 UpdateCommandsForFind();
1136 // Update the zoom commands when an active tab is selected.
1137 UpdateCommandsForZoomState();
1140 void BrowserCommandController::UpdateCommandsForZoomState() {
1141 WebContents
* contents
=
1142 browser_
->tab_strip_model()->GetActiveWebContents();
1145 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_PLUS
,
1146 CanZoomIn(contents
));
1147 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_NORMAL
,
1148 CanResetZoom(contents
));
1149 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MINUS
,
1150 CanZoomOut(contents
));
1153 void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1154 int restrictions
= GetContentRestrictions(browser_
);
1156 command_updater_
.UpdateCommandEnabled(
1157 IDC_COPY
, !(restrictions
& CONTENT_RESTRICTION_COPY
));
1158 command_updater_
.UpdateCommandEnabled(
1159 IDC_CUT
, !(restrictions
& CONTENT_RESTRICTION_CUT
));
1160 command_updater_
.UpdateCommandEnabled(
1161 IDC_PASTE
, !(restrictions
& CONTENT_RESTRICTION_PASTE
));
1162 UpdateSaveAsState();
1163 UpdatePrintingState();
1166 void BrowserCommandController::UpdateCommandsForDevTools() {
1167 bool dev_tools_enabled
=
1168 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled
);
1169 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS
,
1171 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE
,
1173 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES
,
1175 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT
,
1177 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE
,
1181 void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1182 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_PAGE
,
1183 CanBookmarkCurrentPage(browser_
));
1184 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS
,
1185 CanBookmarkAllTabs(browser_
));
1187 command_updater_
.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN
, true);
1191 void BrowserCommandController::UpdateCommandsForBookmarkBar() {
1192 command_updater_
.UpdateCommandEnabled(
1193 IDC_SHOW_BOOKMARK_BAR
,
1194 browser_defaults::bookmarks_enabled
&& !profile()->IsGuestSession() &&
1195 !profile()->GetPrefs()->IsManagedPreference(
1196 bookmarks::prefs::kShowBookmarkBar
) &&
1200 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1201 UpdateSaveAsState();
1202 UpdateOpenFileState(&command_updater_
);
1205 void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1206 WindowState window_state
= WINDOW_STATE_NOT_FULLSCREEN
;
1207 if (window() && window()->IsFullscreen()) {
1208 window_state
= WINDOW_STATE_FULLSCREEN
;
1210 if (window()->IsInMetroSnapMode())
1211 window_state
= WINDOW_STATE_METRO_SNAP
;
1214 bool show_main_ui
= IsShowingMainUI();
1215 bool main_not_fullscreen
=
1216 show_main_ui
&& window_state
== WINDOW_STATE_NOT_FULLSCREEN
;
1218 // Navigation commands
1219 command_updater_
.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL
, show_main_ui
);
1221 // Window management commands
1222 command_updater_
.UpdateCommandEnabled(
1224 !browser_
->is_type_tabbed() &&
1225 window_state
== WINDOW_STATE_NOT_FULLSCREEN
);
1227 // Focus various bits of UI
1228 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR
, show_main_ui
);
1229 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_LOCATION
, show_main_ui
);
1230 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_SEARCH
, show_main_ui
);
1231 command_updater_
.UpdateCommandEnabled(
1232 IDC_FOCUS_MENU_BAR
, main_not_fullscreen
);
1233 command_updater_
.UpdateCommandEnabled(
1234 IDC_FOCUS_NEXT_PANE
, main_not_fullscreen
);
1235 command_updater_
.UpdateCommandEnabled(
1236 IDC_FOCUS_PREVIOUS_PANE
, main_not_fullscreen
);
1237 command_updater_
.UpdateCommandEnabled(
1238 IDC_FOCUS_BOOKMARKS
, main_not_fullscreen
);
1239 command_updater_
.UpdateCommandEnabled(
1240 IDC_FOCUS_INFOBARS
, main_not_fullscreen
);
1242 // Show various bits of UI
1243 command_updater_
.UpdateCommandEnabled(IDC_DEVELOPER_MENU
, show_main_ui
);
1244 #if defined(GOOGLE_CHROME_BUILD)
1245 command_updater_
.UpdateCommandEnabled(IDC_FEEDBACK
, show_main_ui
);
1247 UpdateShowSyncState(show_main_ui
);
1249 // Settings page/subpages are forced to open in normal mode. We disable these
1250 // commands for guest sessions and when incognito is forced.
1251 const bool options_enabled
= show_main_ui
&&
1252 IncognitoModePrefs::GetAvailability(
1253 profile()->GetPrefs()) != IncognitoModePrefs::FORCED
;
1254 const bool guest_session
= profile()->IsGuestSession();
1255 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
, options_enabled
);
1256 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
,
1257 options_enabled
&& !guest_session
);
1259 command_updater_
.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES
, show_main_ui
);
1260 command_updater_
.UpdateCommandEnabled(IDC_VIEW_PASSWORDS
, show_main_ui
);
1261 command_updater_
.UpdateCommandEnabled(IDC_ABOUT
, show_main_ui
);
1262 command_updater_
.UpdateCommandEnabled(IDC_SHOW_APP_MENU
, show_main_ui
);
1263 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC)
1264 command_updater_
.UpdateCommandEnabled(IDC_PROFILING_ENABLED
, show_main_ui
);
1267 // Disable explicit fullscreen toggling when in metro snap mode.
1268 bool fullscreen_enabled
= window_state
!= WINDOW_STATE_METRO_SNAP
;
1269 #if !defined(OS_MACOSX)
1270 if (window_state
== WINDOW_STATE_NOT_FULLSCREEN
&&
1271 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed
)) {
1272 // Disable toggling into fullscreen mode if disallowed by pref.
1273 fullscreen_enabled
= false;
1277 command_updater_
.UpdateCommandEnabled(IDC_FULLSCREEN
, fullscreen_enabled
);
1278 command_updater_
.UpdateCommandEnabled(IDC_PRESENTATION_MODE
,
1279 fullscreen_enabled
);
1281 UpdateCommandsForBookmarkBar();
1284 void BrowserCommandController::UpdatePrintingState() {
1285 bool print_enabled
= CanPrint(browser_
);
1286 command_updater_
.UpdateCommandEnabled(IDC_PRINT
, print_enabled
);
1287 #if defined(ENABLE_BASIC_PRINTING)
1288 command_updater_
.UpdateCommandEnabled(IDC_BASIC_PRINT
,
1289 CanBasicPrint(browser_
));
1290 #endif // ENABLE_BASIC_PRINTING
1293 void BrowserCommandController::UpdateSaveAsState() {
1294 command_updater_
.UpdateCommandEnabled(IDC_SAVE_PAGE
, CanSavePage(browser_
));
1297 void BrowserCommandController::UpdateShowSyncState(bool show_main_ui
) {
1298 command_updater_
.UpdateCommandEnabled(
1299 IDC_SHOW_SYNC_SETUP
, show_main_ui
&& pref_signin_allowed_
.GetValue());
1303 void BrowserCommandController::UpdateOpenFileState(
1304 CommandUpdater
* command_updater
) {
1305 bool enabled
= true;
1306 PrefService
* local_state
= g_browser_process
->local_state();
1308 enabled
= local_state
->GetBoolean(prefs::kAllowFileSelectionDialogs
);
1310 command_updater
->UpdateCommandEnabled(IDC_OPEN_FILE
, enabled
);
1313 void BrowserCommandController::UpdateReloadStopState(bool is_loading
,
1315 window()->UpdateReloadStopState(is_loading
, force
);
1316 command_updater_
.UpdateCommandEnabled(IDC_STOP
, is_loading
);
1319 void BrowserCommandController::UpdateTabRestoreCommandState() {
1320 TabRestoreService
* tab_restore_service
=
1321 TabRestoreServiceFactory::GetForProfile(profile());
1322 // The command is enabled if the service hasn't loaded yet to trigger loading.
1323 // The command is updated once the load completes.
1324 command_updater_
.UpdateCommandEnabled(
1326 tab_restore_service
&&
1327 (!tab_restore_service
->IsLoaded() ||
1328 GetRestoreTabType(browser_
) != TabStripModelDelegate::RESTORE_NONE
));
1331 void BrowserCommandController::UpdateCommandsForFind() {
1332 TabStripModel
* model
= browser_
->tab_strip_model();
1333 bool enabled
= !model
->IsTabBlocked(model
->active_index()) &&
1334 !browser_
->is_devtools();
1336 command_updater_
.UpdateCommandEnabled(IDC_FIND
, enabled
);
1337 command_updater_
.UpdateCommandEnabled(IDC_FIND_NEXT
, enabled
);
1338 command_updater_
.UpdateCommandEnabled(IDC_FIND_PREVIOUS
, enabled
);
1341 void BrowserCommandController::AddInterstitialObservers(WebContents
* contents
) {
1342 interstitial_observers_
.push_back(new InterstitialObserver(this, contents
));
1345 void BrowserCommandController::RemoveInterstitialObservers(
1346 WebContents
* contents
) {
1347 for (size_t i
= 0; i
< interstitial_observers_
.size(); i
++) {
1348 if (interstitial_observers_
[i
]->web_contents() != contents
)
1351 delete interstitial_observers_
[i
];
1352 interstitial_observers_
.erase(interstitial_observers_
.begin() + i
);
1357 BrowserWindow
* BrowserCommandController::window() {
1358 return browser_
->window();
1361 Profile
* BrowserCommandController::profile() {
1362 return browser_
->profile();
1365 } // namespace chrome