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/lifetime/application_lifetime.h"
15 #include "chrome/browser/prefs/incognito_mode_prefs.h"
16 #include "chrome/browser/profiles/avatar_menu.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 "ui/events/keycodes/keyboard_codes.h"
46 #if defined(OS_MACOSX)
47 #include "chrome/browser/ui/browser_commands_mac.h"
51 #include "base/win/metro.h"
52 #include "base/win/windows_version.h"
53 #include "chrome/browser/ui/apps/apps_metro_handler_win.h"
54 #include "content/public/browser/gpu_data_manager.h"
58 #include "ash/accelerators/accelerator_commands.h"
59 #include "chrome/browser/ui/ash/ash_util.h"
62 #if defined(OS_CHROMEOS)
63 #include "ash/multi_profile_uma.h"
64 #include "ash/session_state_delegate.h"
65 #include "ash/shell.h"
66 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
67 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
68 #include "chrome/browser/ui/browser_commands_chromeos.h"
71 #if defined(USE_X11) && !defined(OS_CHROMEOS)
72 #include "ui/events/x/text_edit_key_bindings_delegate_x11.h"
75 using content::NavigationEntry
;
76 using content::NavigationController
;
77 using content::WebContents
;
82 // Not in fullscreen mode.
83 WINDOW_STATE_NOT_FULLSCREEN
,
85 // Fullscreen mode, occupying the whole screen.
86 WINDOW_STATE_FULLSCREEN
,
88 // Fullscreen mode for metro snap, occupying the full height and 20% of
90 WINDOW_STATE_METRO_SNAP
,
93 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
94 bool HasInternalURL(const NavigationEntry
* entry
) {
98 // Check the |virtual_url()| first. This catches regular chrome:// URLs
99 // including URLs that were rewritten (such as chrome://bookmarks).
100 if (entry
->GetVirtualURL().SchemeIs(content::kChromeUIScheme
))
103 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
104 // view-source: of a chrome:// URL.
105 if (entry
->GetVirtualURL().SchemeIs(content::kViewSourceScheme
))
106 return entry
->GetURL().SchemeIs(content::kChromeUIScheme
);
112 // Windows 8 specific helper class to manage DefaultBrowserWorker. It does the
113 // following asynchronous actions in order:
114 // 1- Check that chrome is the default browser
115 // 2- If we are the default, restart chrome in metro and exit
116 // 3- If not the default browser show the 'select default browser' system dialog
117 // 4- When dialog dismisses check again who got made the default
118 // 5- If we are the default then restart chrome in metro and exit
119 // 6- If we are not the default exit.
121 // Note: this class deletes itself.
122 class SwitchToMetroUIHandler
123 : public ShellIntegration::DefaultWebClientObserver
{
125 SwitchToMetroUIHandler()
126 : default_browser_worker_(
127 new ShellIntegration::DefaultBrowserWorker(this)),
129 default_browser_worker_
->StartCheckIsDefault();
132 virtual ~SwitchToMetroUIHandler() {
133 default_browser_worker_
->ObserverDestroyed();
137 virtual void SetDefaultWebClientUIState(
138 ShellIntegration::DefaultWebClientUIState state
) OVERRIDE
{
140 case ShellIntegration::STATE_PROCESSING
:
142 case ShellIntegration::STATE_UNKNOWN
:
144 case ShellIntegration::STATE_IS_DEFAULT
:
145 chrome::AttemptRestartToMetroMode();
147 case ShellIntegration::STATE_NOT_DEFAULT
:
149 default_browser_worker_
->StartSetAsDefault();
159 virtual void OnSetAsDefaultConcluded(bool success
) OVERRIDE
{
164 first_check_
= false;
165 default_browser_worker_
->StartCheckIsDefault();
168 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE
{
172 scoped_refptr
<ShellIntegration::DefaultBrowserWorker
> default_browser_worker_
;
175 DISALLOW_COPY_AND_ASSIGN(SwitchToMetroUIHandler
);
177 #endif // defined(OS_WIN)
183 ///////////////////////////////////////////////////////////////////////////////
184 // BrowserCommandController, public:
186 BrowserCommandController::BrowserCommandController(
188 ProfileManager
* profile_manager
)
190 profile_manager_(profile_manager
),
191 command_updater_(this),
192 block_command_execution_(false),
193 last_blocked_command_id_(-1),
194 last_blocked_command_disposition_(CURRENT_TAB
) {
195 if (profile_manager_
)
196 profile_manager_
->GetProfileInfoCache().AddObserver(this);
197 browser_
->tab_strip_model()->AddObserver(this);
198 PrefService
* local_state
= g_browser_process
->local_state();
200 local_pref_registrar_
.Init(local_state
);
201 local_pref_registrar_
.Add(
202 prefs::kAllowFileSelectionDialogs
,
204 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs
,
205 base::Unretained(this)));
208 profile_pref_registrar_
.Init(profile()->GetPrefs());
209 profile_pref_registrar_
.Add(
210 prefs::kDevToolsDisabled
,
211 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools
,
212 base::Unretained(this)));
213 profile_pref_registrar_
.Add(
214 prefs::kEditBookmarksEnabled
,
215 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing
,
216 base::Unretained(this)));
217 profile_pref_registrar_
.Add(
218 prefs::kShowBookmarkBar
,
219 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar
,
220 base::Unretained(this)));
221 profile_pref_registrar_
.Add(
222 prefs::kIncognitoModeAvailability
,
224 &BrowserCommandController::UpdateCommandsForIncognitoAvailability
,
225 base::Unretained(this)));
226 profile_pref_registrar_
.Add(
227 prefs::kPrintingEnabled
,
228 base::Bind(&BrowserCommandController::UpdatePrintingState
,
229 base::Unretained(this)));
230 #if !defined(OS_MACOSX)
231 profile_pref_registrar_
.Add(
232 prefs::kFullscreenAllowed
,
233 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode
,
234 base::Unretained(this)));
236 pref_signin_allowed_
.Init(
237 prefs::kSigninAllowed
,
238 profile()->GetOriginalProfile()->GetPrefs(),
239 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange
,
240 base::Unretained(this)));
244 TabRestoreService
* tab_restore_service
=
245 TabRestoreServiceFactory::GetForProfile(profile());
246 if (tab_restore_service
) {
247 tab_restore_service
->AddObserver(this);
248 TabRestoreServiceChanged(tab_restore_service
);
252 BrowserCommandController::~BrowserCommandController() {
253 // TabRestoreService may have been shutdown by the time we get here. Don't
254 // trigger creating it.
255 TabRestoreService
* tab_restore_service
=
256 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
257 if (tab_restore_service
)
258 tab_restore_service
->RemoveObserver(this);
259 profile_pref_registrar_
.RemoveAll();
260 local_pref_registrar_
.RemoveAll();
261 browser_
->tab_strip_model()->RemoveObserver(this);
262 if (profile_manager_
)
263 profile_manager_
->GetProfileInfoCache().RemoveObserver(this);
266 bool BrowserCommandController::IsReservedCommandOrKey(
268 const content::NativeWebKeyboardEvent
& event
) {
269 // In Apps mode, no keys are reserved.
270 if (browser_
->is_app())
273 #if defined(OS_CHROMEOS)
274 // On Chrome OS, the top row of keys are mapped to browser actions like
275 // back/forward or refresh. We don't want web pages to be able to change the
276 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
277 // reserve browser back/forward and refresh here.
278 ui::KeyboardCode key_code
=
279 static_cast<ui::KeyboardCode
>(event
.windowsKeyCode
);
280 if ((key_code
== ui::VKEY_BROWSER_BACK
&& command_id
== IDC_BACK
) ||
281 (key_code
== ui::VKEY_BROWSER_FORWARD
&& command_id
== IDC_FORWARD
) ||
282 (key_code
== ui::VKEY_BROWSER_REFRESH
&& command_id
== IDC_RELOAD
)) {
287 if (window()->IsFullscreen() && command_id
== IDC_FULLSCREEN
)
290 #if defined(USE_X11) && !defined(OS_CHROMEOS) && !defined(TOOLKIT_GTK)
291 // If this key was registered by the user as a content editing hotkey, then
292 // it is not reserved.
293 ui::TextEditKeyBindingsDelegateX11
* delegate
=
294 ui::GetTextEditKeyBindingsDelegate();
295 if (delegate
&& event
.os_event
&& delegate
->MatchEvent(*event
.os_event
, NULL
))
299 return command_id
== IDC_CLOSE_TAB
||
300 command_id
== IDC_CLOSE_WINDOW
||
301 command_id
== IDC_NEW_INCOGNITO_WINDOW
||
302 command_id
== IDC_NEW_TAB
||
303 command_id
== IDC_NEW_WINDOW
||
304 command_id
== IDC_RESTORE_TAB
||
305 command_id
== IDC_SELECT_NEXT_TAB
||
306 command_id
== IDC_SELECT_PREVIOUS_TAB
||
307 command_id
== IDC_EXIT
;
310 void BrowserCommandController::SetBlockCommandExecution(bool block
) {
311 block_command_execution_
= block
;
313 last_blocked_command_id_
= -1;
314 last_blocked_command_disposition_
= CURRENT_TAB
;
318 int BrowserCommandController::GetLastBlockedCommand(
319 WindowOpenDisposition
* disposition
) {
321 *disposition
= last_blocked_command_disposition_
;
322 return last_blocked_command_id_
;
325 void BrowserCommandController::TabStateChanged() {
326 UpdateCommandsForTabState();
329 void BrowserCommandController::ContentRestrictionsChanged() {
330 UpdateCommandsForContentRestrictionState();
333 void BrowserCommandController::FullscreenStateChanged() {
334 UpdateCommandsForFullscreenMode();
337 void BrowserCommandController::PrintingStateChanged() {
338 UpdatePrintingState();
341 void BrowserCommandController::LoadingStateChanged(bool is_loading
,
343 UpdateReloadStopState(is_loading
, force
);
346 ////////////////////////////////////////////////////////////////////////////////
347 // BrowserCommandController, CommandUpdaterDelegate implementation:
349 void BrowserCommandController::ExecuteCommandWithDisposition(
351 WindowOpenDisposition disposition
) {
352 // No commands are enabled if there is not yet any selected tab.
353 // TODO(pkasting): It seems like we should not need this, because either
354 // most/all commands should not have been enabled yet anyway or the ones that
355 // are enabled should be global, or safe themselves against having no selected
356 // tab. However, Ben says he tried removing this before and got lots of
357 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
358 // window construction. This probably could use closer examination someday.
359 if (browser_
->tab_strip_model()->active_index() == TabStripModel::kNoTab
)
362 DCHECK(command_updater_
.IsCommandEnabled(id
)) << "Invalid/disabled command "
365 // If command execution is blocked then just record the command and return.
366 if (block_command_execution_
) {
367 // We actually only allow no more than one blocked command, otherwise some
368 // commands maybe lost.
369 DCHECK_EQ(last_blocked_command_id_
, -1);
370 last_blocked_command_id_
= id
;
371 last_blocked_command_disposition_
= disposition
;
375 // The order of commands in this switch statement must match the function
376 // declaration order in browser.h!
378 // Navigation commands
380 GoBack(browser_
, disposition
);
383 GoForward(browser_
, disposition
);
386 Reload(browser_
, disposition
);
388 case IDC_RELOAD_CLEARING_CACHE
:
389 ClearCache(browser_
);
391 case IDC_RELOAD_IGNORING_CACHE
:
392 ReloadIgnoringCache(browser_
, disposition
);
395 Home(browser_
, disposition
);
397 case IDC_OPEN_CURRENT_URL
:
398 OpenCurrentURL(browser_
);
404 // Window management commands
408 case IDC_NEW_INCOGNITO_WINDOW
:
409 NewIncognitoWindow(browser_
);
411 case IDC_CLOSE_WINDOW
:
412 content::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
413 CloseWindow(browser_
);
419 content::RecordAction(base::UserMetricsAction("CloseTabByKey"));
422 case IDC_SELECT_NEXT_TAB
:
423 content::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
424 SelectNextTab(browser_
);
426 case IDC_SELECT_PREVIOUS_TAB
:
427 content::RecordAction(
428 base::UserMetricsAction("Accel_SelectPreviousTab"));
429 SelectPreviousTab(browser_
);
431 case IDC_MOVE_TAB_NEXT
:
432 MoveTabNext(browser_
);
434 case IDC_MOVE_TAB_PREVIOUS
:
435 MoveTabPrevious(browser_
);
437 case IDC_SELECT_TAB_0
:
438 case IDC_SELECT_TAB_1
:
439 case IDC_SELECT_TAB_2
:
440 case IDC_SELECT_TAB_3
:
441 case IDC_SELECT_TAB_4
:
442 case IDC_SELECT_TAB_5
:
443 case IDC_SELECT_TAB_6
:
444 case IDC_SELECT_TAB_7
:
445 SelectNumberedTab(browser_
, id
- IDC_SELECT_TAB_0
);
447 case IDC_SELECT_LAST_TAB
:
448 SelectLastTab(browser_
);
450 case IDC_DUPLICATE_TAB
:
451 DuplicateTab(browser_
);
453 case IDC_RESTORE_TAB
:
454 RestoreTab(browser_
);
456 case IDC_SHOW_AS_TAB
:
457 ConvertPopupToTabbedBrowser(browser_
);
460 #if defined(OS_MACOSX)
461 chrome::ToggleFullscreenWithChromeOrFallback(browser_
);
463 chrome::ToggleFullscreenMode(browser_
);
468 case IDC_TOGGLE_ASH_DESKTOP
:
469 chrome::ToggleAshDesktop();
471 case IDC_MINIMIZE_WINDOW
:
472 content::RecordAction(
473 base::UserMetricsAction("Accel_Toggle_Minimized_M"));
474 ash::accelerators::ToggleMinimized();
476 // If Ash needs many more commands here we should implement a general
477 // mechanism to pass accelerators back into Ash. http://crbug.com/285308
480 #if defined(OS_CHROMEOS)
481 case IDC_VISIT_DESKTOP_OF_LRU_USER_2
:
482 case IDC_VISIT_DESKTOP_OF_LRU_USER_3
:
483 ExecuteVisitDesktopCommand(id
, browser_
->window()->GetNativeWindow());
487 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(TOOLKIT_GTK)
488 case IDC_USE_SYSTEM_TITLE_BAR
: {
489 PrefService
* prefs
= browser_
->profile()->GetPrefs();
490 prefs
->SetBoolean(prefs::kUseCustomChromeFrame
,
491 !prefs
->GetBoolean(prefs::kUseCustomChromeFrame
));
497 // Windows 8 specific commands.
498 case IDC_METRO_SNAP_ENABLE
:
499 browser_
->SetMetroSnapMode(true);
501 case IDC_METRO_SNAP_DISABLE
:
502 browser_
->SetMetroSnapMode(false);
504 case IDC_WIN8_DESKTOP_RESTART
:
505 if (!VerifyMetroSwitchForApps(window()->GetNativeWindow(), id
))
508 chrome::AttemptRestartToDesktopMode();
509 content::RecordAction(base::UserMetricsAction("Win8DesktopRestart"));
511 case IDC_WIN8_METRO_RESTART
:
512 if (!VerifyMetroSwitchForApps(window()->GetNativeWindow(), id
))
515 // SwitchToMetroUIHandler deletes itself.
516 new SwitchToMetroUIHandler
;
517 content::RecordAction(base::UserMetricsAction("Win8MetroRestart"));
521 #if defined(OS_MACOSX)
522 case IDC_PRESENTATION_MODE
:
523 chrome::ToggleFullscreenMode(browser_
);
530 // Page-related commands
534 case IDC_BOOKMARK_PAGE
:
535 BookmarkCurrentPage(browser_
);
537 case IDC_BOOKMARK_PAGE_FROM_STAR
:
538 BookmarkCurrentPageFromStar(browser_
);
540 case IDC_PIN_TO_START_SCREEN
:
541 TogglePagePinnedToStartScreen(browser_
);
543 case IDC_BOOKMARK_ALL_TABS
:
544 BookmarkAllTabs(browser_
);
546 case IDC_VIEW_SOURCE
:
547 ViewSelectedSource(browser_
);
549 case IDC_EMAIL_PAGE_LOCATION
:
550 EmailPageLocation(browser_
);
555 case IDC_ADVANCED_PRINT
:
556 content::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
557 AdvancedPrint(browser_
);
559 case IDC_PRINT_TO_DESTINATION
:
560 PrintToDestination(browser_
);
562 case IDC_TRANSLATE_PAGE
:
565 case IDC_ENCODING_AUTO_DETECT
:
566 browser_
->ToggleEncodingAutoDetect();
568 case IDC_ENCODING_UTF8
:
569 case IDC_ENCODING_UTF16LE
:
570 case IDC_ENCODING_ISO88591
:
571 case IDC_ENCODING_WINDOWS1252
:
572 case IDC_ENCODING_GBK
:
573 case IDC_ENCODING_GB18030
:
574 case IDC_ENCODING_BIG5HKSCS
:
575 case IDC_ENCODING_BIG5
:
576 case IDC_ENCODING_KOREAN
:
577 case IDC_ENCODING_SHIFTJIS
:
578 case IDC_ENCODING_ISO2022JP
:
579 case IDC_ENCODING_EUCJP
:
580 case IDC_ENCODING_THAI
:
581 case IDC_ENCODING_ISO885915
:
582 case IDC_ENCODING_MACINTOSH
:
583 case IDC_ENCODING_ISO88592
:
584 case IDC_ENCODING_WINDOWS1250
:
585 case IDC_ENCODING_ISO88595
:
586 case IDC_ENCODING_WINDOWS1251
:
587 case IDC_ENCODING_KOI8R
:
588 case IDC_ENCODING_KOI8U
:
589 case IDC_ENCODING_ISO88597
:
590 case IDC_ENCODING_WINDOWS1253
:
591 case IDC_ENCODING_ISO88594
:
592 case IDC_ENCODING_ISO885913
:
593 case IDC_ENCODING_WINDOWS1257
:
594 case IDC_ENCODING_ISO88593
:
595 case IDC_ENCODING_ISO885910
:
596 case IDC_ENCODING_ISO885914
:
597 case IDC_ENCODING_ISO885916
:
598 case IDC_ENCODING_WINDOWS1254
:
599 case IDC_ENCODING_ISO88596
:
600 case IDC_ENCODING_WINDOWS1256
:
601 case IDC_ENCODING_ISO88598
:
602 case IDC_ENCODING_ISO88598I
:
603 case IDC_ENCODING_WINDOWS1255
:
604 case IDC_ENCODING_WINDOWS1258
:
605 browser_
->OverrideEncoding(id
);
608 // Clipboard commands
626 case IDC_FIND_PREVIOUS
:
627 FindPrevious(browser_
);
632 Zoom(browser_
, content::PAGE_ZOOM_IN
);
634 case IDC_ZOOM_NORMAL
:
635 Zoom(browser_
, content::PAGE_ZOOM_RESET
);
638 Zoom(browser_
, content::PAGE_ZOOM_OUT
);
641 // Focus various bits of UI
642 case IDC_FOCUS_TOOLBAR
:
643 content::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
644 FocusToolbar(browser_
);
646 case IDC_FOCUS_LOCATION
:
647 content::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
648 FocusLocationBar(browser_
);
650 case IDC_FOCUS_SEARCH
:
651 content::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
652 FocusSearch(browser_
);
654 case IDC_FOCUS_MENU_BAR
:
655 FocusAppMenu(browser_
);
657 case IDC_FOCUS_BOOKMARKS
:
658 content::RecordAction(
659 base::UserMetricsAction("Accel_Focus_Bookmarks"));
660 FocusBookmarksToolbar(browser_
);
662 case IDC_FOCUS_INFOBARS
:
663 FocusInfobars(browser_
);
665 case IDC_FOCUS_NEXT_PANE
:
666 FocusNextPane(browser_
);
668 case IDC_FOCUS_PREVIOUS_PANE
:
669 FocusPreviousPane(browser_
);
672 // Show various bits of UI
674 browser_
->OpenFile();
676 case IDC_CREATE_SHORTCUTS
:
677 CreateApplicationShortcuts(browser_
);
679 case IDC_CREATE_HOSTED_APP
:
680 CreateHostedAppFromCurrentWebContents(browser_
);
683 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::Show());
685 case IDC_DEV_TOOLS_CONSOLE
:
686 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::ShowConsole());
688 case IDC_DEV_TOOLS_DEVICES
:
689 InspectUI::InspectDevices(browser_
);
691 case IDC_DEV_TOOLS_INSPECT
:
692 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::Inspect());
694 case IDC_DEV_TOOLS_TOGGLE
:
695 ToggleDevToolsWindow(browser_
, DevToolsToggleAction::Toggle());
697 case IDC_TASK_MANAGER
:
698 OpenTaskManager(browser_
);
700 #if defined(OS_CHROMEOS)
701 case IDC_TAKE_SCREENSHOT
:
705 #if defined(GOOGLE_CHROME_BUILD)
707 OpenFeedbackDialog(browser_
);
710 case IDC_SHOW_BOOKMARK_BAR
:
711 ToggleBookmarkBar(browser_
);
713 case IDC_PROFILING_ENABLED
:
717 case IDC_SHOW_BOOKMARK_MANAGER
:
718 ShowBookmarkManager(browser_
);
720 case IDC_SHOW_APP_MENU
:
721 content::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
722 ShowAppMenu(browser_
);
724 case IDC_SHOW_AVATAR_MENU
:
725 ShowAvatarMenu(browser_
);
727 case IDC_SHOW_HISTORY
:
728 ShowHistory(browser_
);
730 case IDC_SHOW_DOWNLOADS
:
731 ShowDownloads(browser_
);
733 case IDC_MANAGE_EXTENSIONS
:
734 ShowExtensions(browser_
, std::string());
737 ShowSettings(browser_
);
739 case IDC_EDIT_SEARCH_ENGINES
:
740 ShowSearchEngineSettings(browser_
);
742 case IDC_VIEW_PASSWORDS
:
743 ShowPasswordManager(browser_
);
745 case IDC_CLEAR_BROWSING_DATA
:
746 ShowClearBrowsingDataDialog(browser_
);
748 case IDC_IMPORT_SETTINGS
:
749 ShowImportDialog(browser_
);
751 case IDC_TOGGLE_REQUEST_TABLET_SITE
:
752 ToggleRequestTabletSite(browser_
);
755 ShowAboutChrome(browser_
);
757 case IDC_UPGRADE_DIALOG
:
758 OpenUpdateChromeDialog(browser_
);
760 case IDC_VIEW_INCOMPATIBILITIES
:
761 ShowConflicts(browser_
);
763 case IDC_HELP_PAGE_VIA_KEYBOARD
:
764 ShowHelp(browser_
, HELP_SOURCE_KEYBOARD
);
766 case IDC_HELP_PAGE_VIA_MENU
:
767 ShowHelp(browser_
, HELP_SOURCE_MENU
);
769 case IDC_SHOW_SIGNIN
:
770 ShowBrowserSignin(browser_
, signin::SOURCE_MENU
);
772 case IDC_TOGGLE_SPEECH_INPUT
:
773 ToggleSpeechInput(browser_
);
777 LOG(WARNING
) << "Received Unimplemented Command: " << id
;
782 ////////////////////////////////////////////////////////////////////////////////
783 // BrowserCommandController, ProfileInfoCacheObserver implementation:
785 void BrowserCommandController::OnProfileAdded(
786 const base::FilePath
& profile_path
) {
787 UpdateCommandsForMultipleProfiles();
790 void BrowserCommandController::OnProfileWasRemoved(
791 const base::FilePath
& profile_path
,
792 const base::string16
& profile_name
) {
793 UpdateCommandsForMultipleProfiles();
796 ////////////////////////////////////////////////////////////////////////////////
797 // BrowserCommandController, SigninPrefObserver implementation:
799 void BrowserCommandController::OnSigninAllowedPrefChange() {
800 // For unit tests, we don't have a window.
803 UpdateShowSyncState(IsShowingMainUI());
806 // BrowserCommandController, TabStripModelObserver implementation:
808 void BrowserCommandController::TabInsertedAt(WebContents
* contents
,
811 AddInterstitialObservers(contents
);
814 void BrowserCommandController::TabDetachedAt(WebContents
* contents
, int index
) {
815 RemoveInterstitialObservers(contents
);
818 void BrowserCommandController::TabReplacedAt(TabStripModel
* tab_strip_model
,
819 WebContents
* old_contents
,
820 WebContents
* new_contents
,
822 RemoveInterstitialObservers(old_contents
);
823 AddInterstitialObservers(new_contents
);
826 void BrowserCommandController::TabBlockedStateChanged(
827 content::WebContents
* contents
,
829 PrintingStateChanged();
830 FullscreenStateChanged();
831 UpdateCommandsForFind();
834 ////////////////////////////////////////////////////////////////////////////////
835 // BrowserCommandController, TabRestoreServiceObserver implementation:
837 void BrowserCommandController::TabRestoreServiceChanged(
838 TabRestoreService
* service
) {
839 command_updater_
.UpdateCommandEnabled(
841 GetRestoreTabType(browser_
) != TabStripModelDelegate::RESTORE_NONE
);
844 void BrowserCommandController::TabRestoreServiceDestroyed(
845 TabRestoreService
* service
) {
846 service
->RemoveObserver(this);
849 ////////////////////////////////////////////////////////////////////////////////
850 // BrowserCommandController, private:
852 class BrowserCommandController::InterstitialObserver
853 : public content::WebContentsObserver
{
855 InterstitialObserver(BrowserCommandController
* controller
,
856 content::WebContents
* web_contents
)
857 : WebContentsObserver(web_contents
),
858 controller_(controller
) {
861 using content::WebContentsObserver::web_contents
;
863 virtual void DidAttachInterstitialPage() OVERRIDE
{
864 controller_
->UpdateCommandsForTabState();
867 virtual void DidDetachInterstitialPage() OVERRIDE
{
868 controller_
->UpdateCommandsForTabState();
872 BrowserCommandController
* controller_
;
874 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver
);
877 bool BrowserCommandController::IsShowingMainUI() {
878 bool should_hide_ui
= window() && window()->ShouldHideUIForFullscreen();
879 return browser_
->is_type_tabbed() && !should_hide_ui
;
882 void BrowserCommandController::InitCommandState() {
883 // All browser commands whose state isn't set automagically some other way
884 // (like Back & Forward with initial page load) must have their state
885 // initialized here, otherwise they will be forever disabled.
887 // Navigation commands
888 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, true);
889 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
, true);
890 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
, true);
892 // Window management commands
893 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_WINDOW
, true);
894 command_updater_
.UpdateCommandEnabled(IDC_NEW_TAB
, true);
895 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_TAB
, true);
896 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
, true);
897 command_updater_
.UpdateCommandEnabled(IDC_RESTORE_TAB
, false);
898 #if defined(OS_WIN) && defined(USE_ASH)
899 if (browser_
->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH
)
900 command_updater_
.UpdateCommandEnabled(IDC_EXIT
, true);
902 command_updater_
.UpdateCommandEnabled(IDC_EXIT
, true);
904 command_updater_
.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE
, true);
905 #if defined(OS_WIN) && defined(USE_ASH) && !defined(NDEBUG)
906 if (base::win::GetVersion() < base::win::VERSION_WIN8
&&
907 chrome::HOST_DESKTOP_TYPE_NATIVE
!= chrome::HOST_DESKTOP_TYPE_ASH
)
908 command_updater_
.UpdateCommandEnabled(IDC_TOGGLE_ASH_DESKTOP
, true);
911 command_updater_
.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW
, true);
913 #if defined(OS_CHROMEOS)
914 command_updater_
.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2
, true);
915 command_updater_
.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3
, true);
917 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(TOOLKIT_GTK)
918 command_updater_
.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR
, true);
921 // Page-related commands
922 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
, true);
923 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR
, true);
924 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT
, true);
925 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF8
, true);
926 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF16LE
, true);
927 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88591
, true);
928 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252
, true);
929 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GBK
, true);
930 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GB18030
, true);
931 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS
, true);
932 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5
, true);
933 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_THAI
, true);
934 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOREAN
, true);
935 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS
, true);
936 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP
, true);
937 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_EUCJP
, true);
938 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885915
, true);
939 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH
, true);
940 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88592
, true);
941 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250
, true);
942 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88595
, true);
943 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251
, true);
944 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8R
, true);
945 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8U
, true);
946 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88597
, true);
947 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253
, true);
948 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88594
, true);
949 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885913
, true);
950 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257
, true);
951 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88593
, true);
952 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885910
, true);
953 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885914
, true);
954 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885916
, true);
955 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254
, true);
956 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88596
, true);
957 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256
, true);
958 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598
, true);
959 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598I
, true);
960 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255
, true);
961 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258
, true);
964 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MENU
, true);
965 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_PLUS
, true);
966 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_NORMAL
, true);
967 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MINUS
, true);
969 // Show various bits of UI
970 UpdateOpenFileState(&command_updater_
);
971 command_updater_
.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS
, false);
972 UpdateCommandsForDevTools();
973 command_updater_
.UpdateCommandEnabled(IDC_TASK_MANAGER
, CanOpenTaskManager());
974 command_updater_
.UpdateCommandEnabled(IDC_SHOW_HISTORY
,
975 !profile()->IsGuestSession());
976 command_updater_
.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS
, true);
977 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD
, true);
978 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU
, true);
979 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARKS_MENU
,
980 !profile()->IsGuestSession());
981 command_updater_
.UpdateCommandEnabled(IDC_RECENT_TABS_MENU
,
982 !profile()->IsGuestSession() &&
983 !profile()->IsOffTheRecord());
984 #if defined(OS_CHROMEOS)
985 command_updater_
.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT
, true);
988 UpdateShowSyncState(true);
990 // Initialize other commands based on the window type.
991 bool normal_window
= browser_
->is_type_tabbed();
993 // Navigation commands
994 command_updater_
.UpdateCommandEnabled(
996 normal_window
|| (CommandLine::ForCurrentProcess()->HasSwitch(
997 switches::kEnableStreamlinedHostedApps
) &&
998 browser_
->is_app()));
1000 // Window management commands
1001 command_updater_
.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB
, normal_window
);
1002 command_updater_
.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB
,
1004 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT
, normal_window
);
1005 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS
, normal_window
);
1006 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_0
, normal_window
);
1007 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_1
, normal_window
);
1008 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_2
, normal_window
);
1009 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_3
, normal_window
);
1010 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_4
, normal_window
);
1011 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_5
, normal_window
);
1012 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_6
, normal_window
);
1013 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_7
, normal_window
);
1014 command_updater_
.UpdateCommandEnabled(IDC_SELECT_LAST_TAB
, normal_window
);
1016 #if !defined(USE_AURA)
1017 const bool metro_mode
= base::win::IsMetroProcess();
1019 const bool metro_mode
=
1020 browser_
->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH
?
1023 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE
, metro_mode
);
1024 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE
, metro_mode
);
1025 int restart_mode
= metro_mode
?
1026 IDC_WIN8_DESKTOP_RESTART
: IDC_WIN8_METRO_RESTART
;
1027 command_updater_
.UpdateCommandEnabled(restart_mode
, normal_window
);
1030 // Show various bits of UI
1031 command_updater_
.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA
, normal_window
);
1033 // The upgrade entry and the view incompatibility entry should always be
1034 // enabled. Whether they are visible is a separate matter determined on menu
1036 command_updater_
.UpdateCommandEnabled(IDC_UPGRADE_DIALOG
, true);
1037 command_updater_
.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES
, true);
1039 // Toggle speech input
1040 command_updater_
.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT
, true);
1042 // Initialize other commands whose state changes based on fullscreen mode.
1043 UpdateCommandsForFullscreenMode();
1045 UpdateCommandsForContentRestrictionState();
1047 UpdateCommandsForBookmarkEditing();
1049 UpdateCommandsForIncognitoAvailability();
1053 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1054 CommandUpdater
* command_updater
,
1056 IncognitoModePrefs::Availability incognito_availability
=
1057 IncognitoModePrefs::GetAvailability(profile
->GetPrefs());
1058 command_updater
->UpdateCommandEnabled(
1060 incognito_availability
!= IncognitoModePrefs::FORCED
);
1061 command_updater
->UpdateCommandEnabled(
1062 IDC_NEW_INCOGNITO_WINDOW
,
1063 incognito_availability
!= IncognitoModePrefs::DISABLED
);
1065 // Bookmark manager and settings page/subpages are forced to open in normal
1066 // mode. For this reason we disable these commands when incognito is forced.
1067 const bool command_enabled
=
1068 incognito_availability
!= IncognitoModePrefs::FORCED
&&
1069 !profile
->IsGuestSession();
1070 command_updater
->UpdateCommandEnabled(
1071 IDC_SHOW_BOOKMARK_MANAGER
,
1072 browser_defaults::bookmarks_enabled
&& command_enabled
);
1073 ExtensionService
* extension_service
= profile
->GetExtensionService();
1074 bool enable_extensions
=
1075 extension_service
&& extension_service
->extensions_enabled();
1076 command_updater
->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS
,
1077 enable_extensions
&& command_enabled
);
1079 command_updater
->UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, command_enabled
);
1080 command_updater
->UpdateCommandEnabled(IDC_OPTIONS
, command_enabled
);
1081 command_updater
->UpdateCommandEnabled(IDC_SHOW_SIGNIN
, command_enabled
);
1084 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
1085 UpdateSharedCommandsForIncognitoAvailability(&command_updater_
, profile());
1087 if (!IsShowingMainUI()) {
1088 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, false);
1089 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
, false);
1093 void BrowserCommandController::UpdateCommandsForTabState() {
1094 WebContents
* current_web_contents
=
1095 browser_
->tab_strip_model()->GetActiveWebContents();
1096 if (!current_web_contents
) // May be NULL during tab restore.
1099 // Navigation commands
1100 command_updater_
.UpdateCommandEnabled(IDC_BACK
, CanGoBack(browser_
));
1101 command_updater_
.UpdateCommandEnabled(IDC_FORWARD
, CanGoForward(browser_
));
1102 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, CanReload(browser_
));
1103 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
,
1104 CanReload(browser_
));
1105 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
,
1106 CanReload(browser_
));
1108 // Window management commands
1109 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
,
1110 !browser_
->is_app() && CanDuplicateTab(browser_
));
1112 // Page-related commands
1113 window()->SetStarredState(
1114 BookmarkTabHelper::FromWebContents(current_web_contents
)->is_starred());
1115 window()->ZoomChangedForActiveTab(false);
1116 command_updater_
.UpdateCommandEnabled(IDC_VIEW_SOURCE
,
1117 CanViewSource(browser_
));
1118 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
,
1119 CanEmailPageLocation(browser_
));
1120 if (browser_
->is_devtools())
1121 command_updater_
.UpdateCommandEnabled(IDC_OPEN_FILE
, false);
1123 // Changing the encoding is not possible on Chrome-internal webpages.
1124 NavigationController
& nc
= current_web_contents
->GetController();
1125 bool is_chrome_internal
= HasInternalURL(nc
.GetActiveEntry()) ||
1126 current_web_contents
->ShowingInterstitialPage();
1127 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MENU
,
1128 !is_chrome_internal
&& current_web_contents
->IsSavable());
1130 // Show various bits of UI
1131 // TODO(pinkerton): Disable app-mode in the model until we implement it
1132 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
1133 #if !defined(OS_MACOSX)
1134 command_updater_
.UpdateCommandEnabled(
1135 IDC_CREATE_SHORTCUTS
,
1136 CanCreateApplicationShortcuts(browser_
));
1137 command_updater_
.UpdateCommandEnabled(
1138 IDC_CREATE_HOSTED_APP
,
1139 CanCreateApplicationShortcuts(browser_
));
1142 command_updater_
.UpdateCommandEnabled(
1143 IDC_TOGGLE_REQUEST_TABLET_SITE
,
1144 CanRequestTabletSite(current_web_contents
));
1146 UpdateCommandsForContentRestrictionState();
1147 UpdateCommandsForBookmarkEditing();
1148 UpdateCommandsForFind();
1151 void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1152 int restrictions
= GetContentRestrictions(browser_
);
1154 command_updater_
.UpdateCommandEnabled(
1155 IDC_COPY
, !(restrictions
& CONTENT_RESTRICTION_COPY
));
1156 command_updater_
.UpdateCommandEnabled(
1157 IDC_CUT
, !(restrictions
& CONTENT_RESTRICTION_CUT
));
1158 command_updater_
.UpdateCommandEnabled(
1159 IDC_PASTE
, !(restrictions
& CONTENT_RESTRICTION_PASTE
));
1160 UpdateSaveAsState();
1161 UpdatePrintingState();
1164 void BrowserCommandController::UpdateCommandsForDevTools() {
1165 bool dev_tools_enabled
=
1166 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled
);
1167 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS
,
1169 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE
,
1171 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES
,
1173 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT
,
1175 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE
,
1179 void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1180 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_PAGE
,
1181 CanBookmarkCurrentPage(browser_
));
1182 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS
,
1183 CanBookmarkAllTabs(browser_
));
1184 command_updater_
.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN
,
1188 void BrowserCommandController::UpdateCommandsForBookmarkBar() {
1189 command_updater_
.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR
,
1190 browser_defaults::bookmarks_enabled
&&
1191 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar
) &&
1195 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1196 UpdateSaveAsState();
1197 UpdateOpenFileState(&command_updater_
);
1200 void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1201 WindowState window_state
= WINDOW_STATE_NOT_FULLSCREEN
;
1202 if (window() && window()->IsFullscreen()) {
1203 window_state
= WINDOW_STATE_FULLSCREEN
;
1205 if (window()->IsInMetroSnapMode())
1206 window_state
= WINDOW_STATE_METRO_SNAP
;
1209 bool show_main_ui
= IsShowingMainUI();
1210 bool main_not_fullscreen
=
1211 show_main_ui
&& window_state
== WINDOW_STATE_NOT_FULLSCREEN
;
1213 // Navigation commands
1214 command_updater_
.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL
, show_main_ui
);
1216 // Window management commands
1217 command_updater_
.UpdateCommandEnabled(
1219 !browser_
->is_type_tabbed() &&
1220 window_state
== WINDOW_STATE_NOT_FULLSCREEN
);
1222 // Focus various bits of UI
1223 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR
, show_main_ui
);
1224 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_LOCATION
, show_main_ui
);
1225 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_SEARCH
, show_main_ui
);
1226 command_updater_
.UpdateCommandEnabled(
1227 IDC_FOCUS_MENU_BAR
, main_not_fullscreen
);
1228 command_updater_
.UpdateCommandEnabled(
1229 IDC_FOCUS_NEXT_PANE
, main_not_fullscreen
);
1230 command_updater_
.UpdateCommandEnabled(
1231 IDC_FOCUS_PREVIOUS_PANE
, main_not_fullscreen
);
1232 command_updater_
.UpdateCommandEnabled(
1233 IDC_FOCUS_BOOKMARKS
, main_not_fullscreen
);
1234 command_updater_
.UpdateCommandEnabled(
1235 IDC_FOCUS_INFOBARS
, main_not_fullscreen
);
1237 // Show various bits of UI
1238 command_updater_
.UpdateCommandEnabled(IDC_DEVELOPER_MENU
, show_main_ui
);
1239 #if defined(GOOGLE_CHROME_BUILD)
1240 command_updater_
.UpdateCommandEnabled(IDC_FEEDBACK
, show_main_ui
);
1242 UpdateShowSyncState(show_main_ui
);
1244 // Settings page/subpages are forced to open in normal mode. We disable these
1245 // commands when incognito is forced.
1246 const bool options_enabled
= show_main_ui
&&
1247 IncognitoModePrefs::GetAvailability(
1248 profile()->GetPrefs()) != IncognitoModePrefs::FORCED
;
1249 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
, options_enabled
);
1250 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, options_enabled
);
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
);
1260 // Disable explicit fullscreen toggling when in metro snap mode.
1261 bool fullscreen_enabled
= window_state
!= WINDOW_STATE_METRO_SNAP
;
1262 #if defined(OS_MACOSX)
1263 // The Mac implementation doesn't support switching to fullscreen while
1264 // a tab modal dialog is displayed.
1265 int tab_index
= chrome::IndexOfFirstBlockedTab(browser_
->tab_strip_model());
1266 bool has_blocked_tab
= tab_index
!= browser_
->tab_strip_model()->count();
1267 fullscreen_enabled
&= !has_blocked_tab
;
1269 if (window_state
== WINDOW_STATE_NOT_FULLSCREEN
&&
1270 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed
)) {
1271 // Disable toggling into fullscreen mode if disallowed by pref.
1272 fullscreen_enabled
= false;
1276 command_updater_
.UpdateCommandEnabled(IDC_FULLSCREEN
, fullscreen_enabled
);
1277 command_updater_
.UpdateCommandEnabled(IDC_PRESENTATION_MODE
,
1278 fullscreen_enabled
);
1280 UpdateCommandsForBookmarkBar();
1281 UpdateCommandsForMultipleProfiles();
1284 void BrowserCommandController::UpdateCommandsForMultipleProfiles() {
1285 bool is_regular_or_guest_session
=
1286 profile()->IsGuestSession() || !profile()->IsOffTheRecord();
1287 bool enable
= IsShowingMainUI() &&
1288 is_regular_or_guest_session
&&
1290 AvatarMenu::ShouldShowAvatarMenu();
1291 command_updater_
.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU
,
1295 void BrowserCommandController::UpdatePrintingState() {
1296 bool print_enabled
= CanPrint(browser_
);
1297 command_updater_
.UpdateCommandEnabled(IDC_PRINT
, print_enabled
);
1298 command_updater_
.UpdateCommandEnabled(IDC_ADVANCED_PRINT
,
1299 CanAdvancedPrint(browser_
));
1300 command_updater_
.UpdateCommandEnabled(IDC_PRINT_TO_DESTINATION
,
1303 HMODULE metro_module
= base::win::GetMetroModule();
1304 if (metro_module
!= NULL
) {
1305 typedef void (*MetroEnablePrinting
)(BOOL
);
1306 MetroEnablePrinting metro_enable_printing
=
1307 reinterpret_cast<MetroEnablePrinting
>(
1308 ::GetProcAddress(metro_module
, "MetroEnablePrinting"));
1309 if (metro_enable_printing
)
1310 metro_enable_printing(print_enabled
);
1315 void BrowserCommandController::UpdateSaveAsState() {
1316 command_updater_
.UpdateCommandEnabled(IDC_SAVE_PAGE
, CanSavePage(browser_
));
1319 void BrowserCommandController::UpdateShowSyncState(bool show_main_ui
) {
1320 command_updater_
.UpdateCommandEnabled(
1321 IDC_SHOW_SYNC_SETUP
, show_main_ui
&& pref_signin_allowed_
.GetValue());
1325 void BrowserCommandController::UpdateOpenFileState(
1326 CommandUpdater
* command_updater
) {
1327 bool enabled
= true;
1328 PrefService
* local_state
= g_browser_process
->local_state();
1330 enabled
= local_state
->GetBoolean(prefs::kAllowFileSelectionDialogs
);
1332 command_updater
->UpdateCommandEnabled(IDC_OPEN_FILE
, enabled
);
1335 void BrowserCommandController::UpdateReloadStopState(bool is_loading
,
1337 window()->UpdateReloadStopState(is_loading
, force
);
1338 command_updater_
.UpdateCommandEnabled(IDC_STOP
, is_loading
);
1341 void BrowserCommandController::UpdateCommandsForFind() {
1342 TabStripModel
* model
= browser_
->tab_strip_model();
1343 bool enabled
= !model
->IsTabBlocked(model
->active_index()) &&
1344 !browser_
->is_devtools();
1346 command_updater_
.UpdateCommandEnabled(IDC_FIND
, enabled
);
1347 command_updater_
.UpdateCommandEnabled(IDC_FIND_NEXT
, enabled
);
1348 command_updater_
.UpdateCommandEnabled(IDC_FIND_PREVIOUS
, enabled
);
1351 void BrowserCommandController::AddInterstitialObservers(WebContents
* contents
) {
1352 interstitial_observers_
.push_back(new InterstitialObserver(this, contents
));
1355 void BrowserCommandController::RemoveInterstitialObservers(
1356 WebContents
* contents
) {
1357 for (size_t i
= 0; i
< interstitial_observers_
.size(); i
++) {
1358 if (interstitial_observers_
[i
]->web_contents() != contents
)
1361 delete interstitial_observers_
[i
];
1362 interstitial_observers_
.erase(interstitial_observers_
.begin() + i
);
1367 BrowserWindow
* BrowserCommandController::window() {
1368 return browser_
->window();
1371 Profile
* BrowserCommandController::profile() {
1372 return browser_
->profile();
1375 } // namespace chrome