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/prefs/pref_service.h"
8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/defaults.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/prefs/incognito_mode_prefs.h"
15 #include "chrome/browser/profiles/avatar_menu_model.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/browser/sessions/tab_restore_service.h"
19 #include "chrome/browser/sessions/tab_restore_service_factory.h"
20 #include "chrome/browser/shell_integration.h"
21 #include "chrome/browser/signin/signin_promo.h"
22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
25 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_commands.h"
27 #include "chrome/browser/ui/browser_window.h"
28 #include "chrome/browser/ui/chrome_pages.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
31 #include "chrome/common/content_restriction.h"
32 #include "chrome/common/pref_names.h"
33 #include "chrome/common/profiling.h"
34 #include "content/public/browser/native_web_keyboard_event.h"
35 #include "content/public/browser/navigation_controller.h"
36 #include "content/public/browser/navigation_entry.h"
37 #include "content/public/browser/user_metrics.h"
38 #include "content/public/browser/web_contents.h"
39 #include "content/public/browser/web_contents_observer.h"
40 #include "content/public/common/url_constants.h"
41 #include "ui/base/keycodes/keyboard_codes.h"
43 #if defined(OS_MACOSX)
44 #include "chrome/browser/ui/browser_commands_mac.h"
48 #include "base/win/metro.h"
49 #include "base/win/windows_version.h"
50 #include "chrome/browser/ui/apps/apps_metro_handler_win.h"
54 #include "chrome/browser/ui/ash/ash_util.h"
57 using content::NavigationEntry
;
58 using content::NavigationController
;
59 using content::WebContents
;
64 // Not in fullscreen mode.
65 WINDOW_STATE_NOT_FULLSCREEN
,
67 // Fullscreen mode, occupying the whole screen.
68 WINDOW_STATE_FULLSCREEN
,
70 // Fullscreen mode for metro snap, occupying the full height and 20% of
72 WINDOW_STATE_METRO_SNAP
,
75 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
76 bool HasInternalURL(const NavigationEntry
* entry
) {
80 // Check the |virtual_url()| first. This catches regular chrome:// URLs
81 // including URLs that were rewritten (such as chrome://bookmarks).
82 if (entry
->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme
))
85 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
86 // view-source: of a chrome:// URL.
87 if (entry
->GetVirtualURL().SchemeIs(content::kViewSourceScheme
))
88 return entry
->GetURL().SchemeIs(chrome::kChromeUIScheme
);
94 // Windows 8 specific helper class to manage DefaultBrowserWorker. It does the
95 // following asynchronous actions in order:
96 // 1- Check that chrome is the default browser
97 // 2- If we are the default, restart chrome in metro and exit
98 // 3- If not the default browser show the 'select default browser' system dialog
99 // 4- When dialog dismisses check again who got made the default
100 // 5- If we are the default then restart chrome in metro and exit
101 // 6- If we are not the default exit.
103 // Note: this class deletes itself.
104 class SwitchToMetroUIHandler
105 : public ShellIntegration::DefaultWebClientObserver
{
107 SwitchToMetroUIHandler()
108 : default_browser_worker_(
109 new ShellIntegration::DefaultBrowserWorker(this)),
111 default_browser_worker_
->StartCheckIsDefault();
114 virtual ~SwitchToMetroUIHandler() {
115 default_browser_worker_
->ObserverDestroyed();
119 virtual void SetDefaultWebClientUIState(
120 ShellIntegration::DefaultWebClientUIState state
) OVERRIDE
{
122 case ShellIntegration::STATE_PROCESSING
:
124 case ShellIntegration::STATE_UNKNOWN
:
126 case ShellIntegration::STATE_IS_DEFAULT
:
127 chrome::AttemptRestartWithModeSwitch();
129 case ShellIntegration::STATE_NOT_DEFAULT
:
131 default_browser_worker_
->StartSetAsDefault();
141 virtual void OnSetAsDefaultConcluded(bool success
) OVERRIDE
{
146 first_check_
= false;
147 default_browser_worker_
->StartCheckIsDefault();
150 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE
{
154 scoped_refptr
<ShellIntegration::DefaultBrowserWorker
> default_browser_worker_
;
157 DISALLOW_COPY_AND_ASSIGN(SwitchToMetroUIHandler
);
159 #endif // defined(OS_WIN)
165 ///////////////////////////////////////////////////////////////////////////////
166 // BrowserCommandController, public:
168 BrowserCommandController::BrowserCommandController(
170 ProfileManager
* profile_manager
)
172 profile_manager_(profile_manager
),
173 command_updater_(this),
174 block_command_execution_(false),
175 last_blocked_command_id_(-1),
176 last_blocked_command_disposition_(CURRENT_TAB
) {
177 if (profile_manager_
)
178 profile_manager_
->GetProfileInfoCache().AddObserver(this);
179 browser_
->tab_strip_model()->AddObserver(this);
180 PrefService
* local_state
= g_browser_process
->local_state();
182 local_pref_registrar_
.Init(local_state
);
183 local_pref_registrar_
.Add(
184 prefs::kAllowFileSelectionDialogs
,
186 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs
,
187 base::Unretained(this)));
190 profile_pref_registrar_
.Init(profile()->GetPrefs());
191 profile_pref_registrar_
.Add(
192 prefs::kDevToolsDisabled
,
193 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools
,
194 base::Unretained(this)));
195 profile_pref_registrar_
.Add(
196 prefs::kEditBookmarksEnabled
,
197 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing
,
198 base::Unretained(this)));
199 profile_pref_registrar_
.Add(
200 prefs::kShowBookmarkBar
,
201 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar
,
202 base::Unretained(this)));
203 profile_pref_registrar_
.Add(
204 prefs::kIncognitoModeAvailability
,
206 &BrowserCommandController::UpdateCommandsForIncognitoAvailability
,
207 base::Unretained(this)));
208 profile_pref_registrar_
.Add(
209 prefs::kPrintingEnabled
,
210 base::Bind(&BrowserCommandController::UpdatePrintingState
,
211 base::Unretained(this)));
212 #if !defined(OS_MACOSX)
213 profile_pref_registrar_
.Add(
214 prefs::kFullscreenAllowed
,
215 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode
,
216 base::Unretained(this)));
218 pref_signin_allowed_
.Init(
219 prefs::kSigninAllowed
,
220 profile()->GetOriginalProfile()->GetPrefs(),
221 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange
,
222 base::Unretained(this)));
226 TabRestoreService
* tab_restore_service
=
227 TabRestoreServiceFactory::GetForProfile(profile());
228 if (tab_restore_service
) {
229 tab_restore_service
->AddObserver(this);
230 TabRestoreServiceChanged(tab_restore_service
);
234 BrowserCommandController::~BrowserCommandController() {
235 // TabRestoreService may have been shutdown by the time we get here. Don't
236 // trigger creating it.
237 TabRestoreService
* tab_restore_service
=
238 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
239 if (tab_restore_service
)
240 tab_restore_service
->RemoveObserver(this);
241 profile_pref_registrar_
.RemoveAll();
242 local_pref_registrar_
.RemoveAll();
243 browser_
->tab_strip_model()->RemoveObserver(this);
244 if (profile_manager_
)
245 profile_manager_
->GetProfileInfoCache().RemoveObserver(this);
248 bool BrowserCommandController::IsReservedCommandOrKey(
250 const content::NativeWebKeyboardEvent
& event
) {
251 // In Apps mode, no keys are reserved.
252 if (browser_
->is_app())
255 #if defined(OS_CHROMEOS)
256 // On Chrome OS, the top row of keys are mapped to browser actions like
257 // back/forward or refresh. We don't want web pages to be able to change the
258 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
259 // reserve browser back/forward and refresh here.
260 ui::KeyboardCode key_code
=
261 static_cast<ui::KeyboardCode
>(event
.windowsKeyCode
);
262 if ((key_code
== ui::VKEY_BROWSER_BACK
&& command_id
== IDC_BACK
) ||
263 (key_code
== ui::VKEY_BROWSER_FORWARD
&& command_id
== IDC_FORWARD
) ||
264 (key_code
== ui::VKEY_BROWSER_REFRESH
&& command_id
== IDC_RELOAD
)) {
269 if (window()->IsFullscreen() && command_id
== IDC_FULLSCREEN
)
271 return command_id
== IDC_CLOSE_TAB
||
272 command_id
== IDC_CLOSE_WINDOW
||
273 command_id
== IDC_NEW_INCOGNITO_WINDOW
||
274 command_id
== IDC_NEW_TAB
||
275 command_id
== IDC_NEW_WINDOW
||
276 command_id
== IDC_RESTORE_TAB
||
277 command_id
== IDC_SELECT_NEXT_TAB
||
278 command_id
== IDC_SELECT_PREVIOUS_TAB
||
279 command_id
== IDC_TABPOSE
||
280 command_id
== IDC_EXIT
;
283 void BrowserCommandController::SetBlockCommandExecution(bool block
) {
284 block_command_execution_
= block
;
286 last_blocked_command_id_
= -1;
287 last_blocked_command_disposition_
= CURRENT_TAB
;
291 int BrowserCommandController::GetLastBlockedCommand(
292 WindowOpenDisposition
* disposition
) {
294 *disposition
= last_blocked_command_disposition_
;
295 return last_blocked_command_id_
;
298 void BrowserCommandController::TabStateChanged() {
299 UpdateCommandsForTabState();
302 void BrowserCommandController::ContentRestrictionsChanged() {
303 UpdateCommandsForContentRestrictionState();
306 void BrowserCommandController::FullscreenStateChanged() {
307 UpdateCommandsForFullscreenMode();
310 void BrowserCommandController::PrintingStateChanged() {
311 UpdatePrintingState();
314 void BrowserCommandController::LoadingStateChanged(bool is_loading
,
316 UpdateReloadStopState(is_loading
, force
);
319 ////////////////////////////////////////////////////////////////////////////////
320 // BrowserCommandController, CommandUpdaterDelegate implementation:
322 void BrowserCommandController::ExecuteCommandWithDisposition(
324 WindowOpenDisposition disposition
) {
325 // No commands are enabled if there is not yet any selected tab.
326 // TODO(pkasting): It seems like we should not need this, because either
327 // most/all commands should not have been enabled yet anyway or the ones that
328 // are enabled should be global, or safe themselves against having no selected
329 // tab. However, Ben says he tried removing this before and got lots of
330 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
331 // window construction. This probably could use closer examination someday.
332 if (browser_
->tab_strip_model()->active_index() == TabStripModel::kNoTab
)
335 DCHECK(command_updater_
.IsCommandEnabled(id
)) << "Invalid/disabled command "
338 // If command execution is blocked then just record the command and return.
339 if (block_command_execution_
) {
340 // We actually only allow no more than one blocked command, otherwise some
341 // commands maybe lost.
342 DCHECK_EQ(last_blocked_command_id_
, -1);
343 last_blocked_command_id_
= id
;
344 last_blocked_command_disposition_
= disposition
;
348 // The order of commands in this switch statement must match the function
349 // declaration order in browser.h!
351 // Navigation commands
353 GoBack(browser_
, disposition
);
356 GoForward(browser_
, disposition
);
359 Reload(browser_
, disposition
);
361 case IDC_RELOAD_CLEARING_CACHE
:
362 ClearCache(browser_
);
364 case IDC_RELOAD_IGNORING_CACHE
:
365 ReloadIgnoringCache(browser_
, disposition
);
368 Home(browser_
, disposition
);
370 case IDC_OPEN_CURRENT_URL
:
371 OpenCurrentURL(browser_
);
377 // Window management commands
381 case IDC_NEW_INCOGNITO_WINDOW
:
382 NewIncognitoWindow(browser_
);
384 case IDC_CLOSE_WINDOW
:
385 content::RecordAction(content::UserMetricsAction("CloseWindowByKey"));
386 CloseWindow(browser_
);
392 content::RecordAction(content::UserMetricsAction("CloseTabByKey"));
395 case IDC_SELECT_NEXT_TAB
:
396 content::RecordAction(content::UserMetricsAction("Accel_SelectNextTab"));
397 SelectNextTab(browser_
);
399 case IDC_SELECT_PREVIOUS_TAB
:
400 content::RecordAction(
401 content::UserMetricsAction("Accel_SelectPreviousTab"));
402 SelectPreviousTab(browser_
);
405 OpenTabpose(browser_
);
407 case IDC_MOVE_TAB_NEXT
:
408 MoveTabNext(browser_
);
410 case IDC_MOVE_TAB_PREVIOUS
:
411 MoveTabPrevious(browser_
);
413 case IDC_SELECT_TAB_0
:
414 case IDC_SELECT_TAB_1
:
415 case IDC_SELECT_TAB_2
:
416 case IDC_SELECT_TAB_3
:
417 case IDC_SELECT_TAB_4
:
418 case IDC_SELECT_TAB_5
:
419 case IDC_SELECT_TAB_6
:
420 case IDC_SELECT_TAB_7
:
421 SelectNumberedTab(browser_
, id
- IDC_SELECT_TAB_0
);
423 case IDC_SELECT_LAST_TAB
:
424 SelectLastTab(browser_
);
426 case IDC_DUPLICATE_TAB
:
427 DuplicateTab(browser_
);
429 case IDC_RESTORE_TAB
:
430 RestoreTab(browser_
);
432 case IDC_SHOW_AS_TAB
:
433 ConvertPopupToTabbedBrowser(browser_
);
436 #if defined(OS_MACOSX)
437 chrome::ToggleFullscreenWithChromeOrFallback(browser_
);
439 chrome::ToggleFullscreenMode(browser_
);
444 case IDC_TOGGLE_ASH_DESKTOP
:
445 chrome::ToggleAshDesktop();
450 // Windows 8 specific commands.
451 case IDC_METRO_SNAP_ENABLE
:
452 browser_
->SetMetroSnapMode(true);
454 case IDC_METRO_SNAP_DISABLE
:
455 browser_
->SetMetroSnapMode(false);
457 case IDC_WIN8_DESKTOP_RESTART
:
458 chrome::AttemptRestartWithModeSwitch();
459 content::RecordAction(content::UserMetricsAction("Win8DesktopRestart"));
461 case IDC_WIN8_METRO_RESTART
:
462 if (!VerifySwitchToMetroForApps(window()->GetNativeWindow()))
465 // SwitchToMetroUIHandler deletes itself.
466 new SwitchToMetroUIHandler
;
467 content::RecordAction(content::UserMetricsAction("Win8MetroRestart"));
471 #if defined(OS_MACOSX)
472 case IDC_PRESENTATION_MODE
:
473 chrome::ToggleFullscreenMode(browser_
);
480 // Page-related commands
484 case IDC_BOOKMARK_PAGE
:
485 BookmarkCurrentPage(browser_
);
487 case IDC_BOOKMARK_PAGE_FROM_STAR
:
488 BookmarkCurrentPageFromStar(browser_
);
490 case IDC_PIN_TO_START_SCREEN
:
491 TogglePagePinnedToStartScreen(browser_
);
493 case IDC_BOOKMARK_ALL_TABS
:
494 BookmarkAllTabs(browser_
);
496 case IDC_VIEW_SOURCE
:
497 ViewSelectedSource(browser_
);
499 case IDC_EMAIL_PAGE_LOCATION
:
500 EmailPageLocation(browser_
);
505 case IDC_ADVANCED_PRINT
:
506 AdvancedPrint(browser_
);
508 case IDC_PRINT_TO_DESTINATION
:
509 PrintToDestination(browser_
);
511 case IDC_ENCODING_AUTO_DETECT
:
512 browser_
->ToggleEncodingAutoDetect();
514 case IDC_ENCODING_UTF8
:
515 case IDC_ENCODING_UTF16LE
:
516 case IDC_ENCODING_ISO88591
:
517 case IDC_ENCODING_WINDOWS1252
:
518 case IDC_ENCODING_GBK
:
519 case IDC_ENCODING_GB18030
:
520 case IDC_ENCODING_BIG5HKSCS
:
521 case IDC_ENCODING_BIG5
:
522 case IDC_ENCODING_KOREAN
:
523 case IDC_ENCODING_SHIFTJIS
:
524 case IDC_ENCODING_ISO2022JP
:
525 case IDC_ENCODING_EUCJP
:
526 case IDC_ENCODING_THAI
:
527 case IDC_ENCODING_ISO885915
:
528 case IDC_ENCODING_MACINTOSH
:
529 case IDC_ENCODING_ISO88592
:
530 case IDC_ENCODING_WINDOWS1250
:
531 case IDC_ENCODING_ISO88595
:
532 case IDC_ENCODING_WINDOWS1251
:
533 case IDC_ENCODING_KOI8R
:
534 case IDC_ENCODING_KOI8U
:
535 case IDC_ENCODING_ISO88597
:
536 case IDC_ENCODING_WINDOWS1253
:
537 case IDC_ENCODING_ISO88594
:
538 case IDC_ENCODING_ISO885913
:
539 case IDC_ENCODING_WINDOWS1257
:
540 case IDC_ENCODING_ISO88593
:
541 case IDC_ENCODING_ISO885910
:
542 case IDC_ENCODING_ISO885914
:
543 case IDC_ENCODING_ISO885916
:
544 case IDC_ENCODING_WINDOWS1254
:
545 case IDC_ENCODING_ISO88596
:
546 case IDC_ENCODING_WINDOWS1256
:
547 case IDC_ENCODING_ISO88598
:
548 case IDC_ENCODING_ISO88598I
:
549 case IDC_ENCODING_WINDOWS1255
:
550 case IDC_ENCODING_WINDOWS1258
:
551 browser_
->OverrideEncoding(id
);
554 // Clipboard commands
572 case IDC_FIND_PREVIOUS
:
573 FindPrevious(browser_
);
578 Zoom(browser_
, content::PAGE_ZOOM_IN
);
580 case IDC_ZOOM_NORMAL
:
581 Zoom(browser_
, content::PAGE_ZOOM_RESET
);
584 Zoom(browser_
, content::PAGE_ZOOM_OUT
);
587 // Focus various bits of UI
588 case IDC_FOCUS_TOOLBAR
:
589 FocusToolbar(browser_
);
591 case IDC_FOCUS_LOCATION
:
592 FocusLocationBar(browser_
);
594 case IDC_FOCUS_SEARCH
:
595 FocusSearch(browser_
);
597 case IDC_FOCUS_MENU_BAR
:
598 FocusAppMenu(browser_
);
600 case IDC_FOCUS_BOOKMARKS
:
601 FocusBookmarksToolbar(browser_
);
603 case IDC_FOCUS_INFOBARS
:
604 FocusInfobars(browser_
);
606 case IDC_FOCUS_NEXT_PANE
:
607 FocusNextPane(browser_
);
609 case IDC_FOCUS_PREVIOUS_PANE
:
610 FocusPreviousPane(browser_
);
613 // Show various bits of UI
615 browser_
->OpenFile();
617 case IDC_CREATE_SHORTCUTS
:
618 CreateApplicationShortcuts(browser_
);
621 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_SHOW
);
623 case IDC_DEV_TOOLS_CONSOLE
:
624 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE
);
626 case IDC_DEV_TOOLS_INSPECT
:
627 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_INSPECT
);
629 case IDC_DEV_TOOLS_TOGGLE
:
630 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_TOGGLE
);
632 case IDC_TASK_MANAGER
:
633 OpenTaskManager(browser_
);
636 OpenFeedbackDialog(browser_
);
639 case IDC_SHOW_BOOKMARK_BAR
:
640 ToggleBookmarkBar(browser_
);
642 case IDC_PROFILING_ENABLED
:
646 case IDC_SHOW_BOOKMARK_MANAGER
:
647 ShowBookmarkManager(browser_
);
649 case IDC_SHOW_APP_MENU
:
650 ShowAppMenu(browser_
);
652 case IDC_SHOW_AVATAR_MENU
:
653 ShowAvatarMenu(browser_
);
655 case IDC_SHOW_HISTORY
:
656 ShowHistory(browser_
);
658 case IDC_SHOW_DOWNLOADS
:
659 ShowDownloads(browser_
);
661 case IDC_MANAGE_EXTENSIONS
:
662 ShowExtensions(browser_
, std::string());
665 ShowSettings(browser_
);
667 case IDC_EDIT_SEARCH_ENGINES
:
668 ShowSearchEngineSettings(browser_
);
670 case IDC_VIEW_PASSWORDS
:
671 ShowPasswordManager(browser_
);
673 case IDC_CLEAR_BROWSING_DATA
:
674 ShowClearBrowsingDataDialog(browser_
);
676 case IDC_IMPORT_SETTINGS
:
677 ShowImportDialog(browser_
);
679 case IDC_TOGGLE_REQUEST_TABLET_SITE
:
680 ToggleRequestTabletSite(browser_
);
683 ShowAboutChrome(browser_
);
685 case IDC_UPGRADE_DIALOG
:
686 OpenUpdateChromeDialog(browser_
);
688 case IDC_VIEW_INCOMPATIBILITIES
:
689 ShowConflicts(browser_
);
691 case IDC_HELP_PAGE_VIA_KEYBOARD
:
692 ShowHelp(browser_
, HELP_SOURCE_KEYBOARD
);
694 case IDC_HELP_PAGE_VIA_MENU
:
695 ShowHelp(browser_
, HELP_SOURCE_MENU
);
697 case IDC_SHOW_SIGNIN
:
698 ShowBrowserSignin(browser_
, signin::SOURCE_MENU
);
700 case IDC_TOGGLE_SPEECH_INPUT
:
701 ToggleSpeechInput(browser_
);
705 LOG(WARNING
) << "Received Unimplemented Command: " << id
;
710 ////////////////////////////////////////////////////////////////////////////////
711 // BrowserCommandController, ProfileInfoCacheObserver implementation:
713 void BrowserCommandController::OnProfileAdded(
714 const base::FilePath
& profile_path
) {
715 UpdateCommandsForMultipleProfiles();
718 void BrowserCommandController::OnProfileWasRemoved(
719 const base::FilePath
& profile_path
,
720 const string16
& profile_name
) {
721 UpdateCommandsForMultipleProfiles();
724 ////////////////////////////////////////////////////////////////////////////////
725 // BrowserCommandController, SigninPrefObserver implementation:
727 void BrowserCommandController::OnSigninAllowedPrefChange() {
728 // For unit tests, we don't have a window.
731 UpdateShowSyncState(IsShowingMainUI());
734 // BrowserCommandController, TabStripModelObserver implementation:
736 void BrowserCommandController::TabInsertedAt(WebContents
* contents
,
739 AddInterstitialObservers(contents
);
742 void BrowserCommandController::TabDetachedAt(WebContents
* contents
, int index
) {
743 RemoveInterstitialObservers(contents
);
746 void BrowserCommandController::TabReplacedAt(TabStripModel
* tab_strip_model
,
747 WebContents
* old_contents
,
748 WebContents
* new_contents
,
750 RemoveInterstitialObservers(old_contents
);
751 AddInterstitialObservers(new_contents
);
754 void BrowserCommandController::TabBlockedStateChanged(
755 content::WebContents
* contents
,
757 PrintingStateChanged();
758 FullscreenStateChanged();
759 UpdateCommandsForFind();
762 ////////////////////////////////////////////////////////////////////////////////
763 // BrowserCommandController, TabRestoreServiceObserver implementation:
765 void BrowserCommandController::TabRestoreServiceChanged(
766 TabRestoreService
* service
) {
767 command_updater_
.UpdateCommandEnabled(
769 GetRestoreTabType(browser_
) != TabStripModelDelegate::RESTORE_NONE
);
772 void BrowserCommandController::TabRestoreServiceDestroyed(
773 TabRestoreService
* service
) {
774 service
->RemoveObserver(this);
777 ////////////////////////////////////////////////////////////////////////////////
778 // BrowserCommandController, private:
780 class BrowserCommandController::InterstitialObserver
781 : public content::WebContentsObserver
{
783 InterstitialObserver(BrowserCommandController
* controller
,
784 content::WebContents
* web_contents
)
785 : WebContentsObserver(web_contents
),
786 controller_(controller
) {
789 using content::WebContentsObserver::web_contents
;
791 virtual void DidAttachInterstitialPage() OVERRIDE
{
792 controller_
->UpdateCommandsForTabState();
795 virtual void DidDetachInterstitialPage() OVERRIDE
{
796 controller_
->UpdateCommandsForTabState();
800 BrowserCommandController
* controller_
;
802 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver
);
805 bool BrowserCommandController::IsShowingMainUI() {
806 bool should_hide_ui
= window() && window()->ShouldHideUIForFullscreen();
807 return browser_
->is_type_tabbed() && !should_hide_ui
;
810 void BrowserCommandController::InitCommandState() {
811 // All browser commands whose state isn't set automagically some other way
812 // (like Back & Forward with initial page load) must have their state
813 // initialized here, otherwise they will be forever disabled.
815 // Navigation commands
816 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, true);
817 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
, true);
818 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
, true);
820 // Window management commands
821 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_WINDOW
, true);
822 command_updater_
.UpdateCommandEnabled(IDC_NEW_TAB
, true);
823 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_TAB
, true);
824 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
, true);
825 command_updater_
.UpdateCommandEnabled(IDC_RESTORE_TAB
, false);
826 #if defined(OS_WIN) && defined(USE_ASH)
827 if (browser_
->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH
)
828 command_updater_
.UpdateCommandEnabled(IDC_EXIT
, true);
830 command_updater_
.UpdateCommandEnabled(IDC_EXIT
, true);
832 command_updater_
.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE
, true);
833 #if defined(OS_WIN) && defined(USE_ASH) && !defined(NDEBUG)
834 if (base::win::GetVersion() < base::win::VERSION_WIN8
&&
835 chrome::HOST_DESKTOP_TYPE_NATIVE
!= chrome::HOST_DESKTOP_TYPE_ASH
)
836 command_updater_
.UpdateCommandEnabled(IDC_TOGGLE_ASH_DESKTOP
, true);
839 // Page-related commands
840 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
, true);
841 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT
, true);
842 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF8
, true);
843 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF16LE
, true);
844 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88591
, true);
845 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252
, true);
846 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GBK
, true);
847 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GB18030
, true);
848 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS
, true);
849 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5
, true);
850 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_THAI
, true);
851 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOREAN
, true);
852 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS
, true);
853 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP
, true);
854 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_EUCJP
, true);
855 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885915
, true);
856 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH
, true);
857 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88592
, true);
858 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250
, true);
859 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88595
, true);
860 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251
, true);
861 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8R
, true);
862 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8U
, true);
863 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88597
, true);
864 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253
, true);
865 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88594
, true);
866 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885913
, true);
867 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257
, true);
868 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88593
, true);
869 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885910
, true);
870 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885914
, true);
871 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885916
, true);
872 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254
, true);
873 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88596
, true);
874 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256
, true);
875 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598
, true);
876 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598I
, true);
877 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255
, true);
878 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258
, true);
881 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MENU
, true);
882 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_PLUS
, true);
883 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_NORMAL
, true);
884 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MINUS
, true);
886 // Show various bits of UI
887 UpdateOpenFileState(&command_updater_
);
888 command_updater_
.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS
, false);
889 UpdateCommandsForDevTools();
890 command_updater_
.UpdateCommandEnabled(IDC_TASK_MANAGER
, CanOpenTaskManager());
891 command_updater_
.UpdateCommandEnabled(IDC_SHOW_HISTORY
,
892 !profile()->IsGuestSession());
893 command_updater_
.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS
, true);
894 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD
, true);
895 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU
, true);
896 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARKS_MENU
,
897 !profile()->IsGuestSession());
898 command_updater_
.UpdateCommandEnabled(IDC_RECENT_TABS_MENU
,
899 !profile()->IsGuestSession() &&
900 !profile()->IsOffTheRecord());
902 UpdateShowSyncState(true);
904 // Initialize other commands based on the window type.
905 bool normal_window
= browser_
->is_type_tabbed();
907 // Navigation commands
908 command_updater_
.UpdateCommandEnabled(IDC_HOME
, normal_window
);
910 // Window management commands
911 command_updater_
.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB
, normal_window
);
912 command_updater_
.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB
,
914 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT
, normal_window
);
915 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS
, normal_window
);
916 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_0
, normal_window
);
917 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_1
, normal_window
);
918 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_2
, normal_window
);
919 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_3
, normal_window
);
920 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_4
, normal_window
);
921 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_5
, normal_window
);
922 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_6
, normal_window
);
923 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_7
, normal_window
);
924 command_updater_
.UpdateCommandEnabled(IDC_SELECT_LAST_TAB
, normal_window
);
926 const bool metro_mode
= base::win::IsMetroProcess();
927 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE
, metro_mode
);
928 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE
, metro_mode
);
929 int restart_mode
= metro_mode
?
930 IDC_WIN8_DESKTOP_RESTART
: IDC_WIN8_METRO_RESTART
;
931 command_updater_
.UpdateCommandEnabled(restart_mode
, normal_window
);
933 command_updater_
.UpdateCommandEnabled(IDC_TABPOSE
, normal_window
);
935 // Show various bits of UI
936 command_updater_
.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA
, normal_window
);
938 // The upgrade entry and the view incompatibility entry should always be
939 // enabled. Whether they are visible is a separate matter determined on menu
941 command_updater_
.UpdateCommandEnabled(IDC_UPGRADE_DIALOG
, true);
942 command_updater_
.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES
, true);
944 // Toggle speech input
945 command_updater_
.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT
, true);
947 // Initialize other commands whose state changes based on fullscreen mode.
948 UpdateCommandsForFullscreenMode();
950 UpdateCommandsForContentRestrictionState();
952 UpdateCommandsForBookmarkEditing();
954 UpdateCommandsForIncognitoAvailability();
958 void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
959 CommandUpdater
* command_updater
,
961 IncognitoModePrefs::Availability incognito_availability
=
962 IncognitoModePrefs::GetAvailability(profile
->GetPrefs());
963 command_updater
->UpdateCommandEnabled(
965 incognito_availability
!= IncognitoModePrefs::FORCED
);
966 command_updater
->UpdateCommandEnabled(
967 IDC_NEW_INCOGNITO_WINDOW
,
968 incognito_availability
!= IncognitoModePrefs::DISABLED
);
970 // Bookmark manager and settings page/subpages are forced to open in normal
971 // mode. For this reason we disable these commands when incognito is forced.
972 const bool command_enabled
=
973 incognito_availability
!= IncognitoModePrefs::FORCED
;
974 command_updater
->UpdateCommandEnabled(
975 IDC_SHOW_BOOKMARK_MANAGER
,
976 browser_defaults::bookmarks_enabled
&& command_enabled
);
977 ExtensionService
* extension_service
= profile
->GetExtensionService();
978 bool enable_extensions
=
979 extension_service
&& extension_service
->extensions_enabled();
980 command_updater
->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS
,
981 enable_extensions
&& command_enabled
);
983 command_updater
->UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, command_enabled
);
984 command_updater
->UpdateCommandEnabled(IDC_OPTIONS
, command_enabled
);
985 command_updater
->UpdateCommandEnabled(IDC_SHOW_SIGNIN
, command_enabled
);
988 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
989 UpdateSharedCommandsForIncognitoAvailability(&command_updater_
, profile());
991 if (!IsShowingMainUI()) {
992 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, false);
993 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
, false);
997 void BrowserCommandController::UpdateCommandsForTabState() {
998 WebContents
* current_web_contents
=
999 browser_
->tab_strip_model()->GetActiveWebContents();
1000 if (!current_web_contents
) // May be NULL during tab restore.
1003 // Navigation commands
1004 command_updater_
.UpdateCommandEnabled(IDC_BACK
, CanGoBack(browser_
));
1005 command_updater_
.UpdateCommandEnabled(IDC_FORWARD
, CanGoForward(browser_
));
1006 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, CanReload(browser_
));
1007 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
,
1008 CanReload(browser_
));
1009 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
,
1010 CanReload(browser_
));
1012 // Window management commands
1013 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
,
1014 !browser_
->is_app() && CanDuplicateTab(browser_
));
1016 // Page-related commands
1017 window()->SetStarredState(
1018 BookmarkTabHelper::FromWebContents(current_web_contents
)->is_starred());
1019 window()->ZoomChangedForActiveTab(false);
1020 command_updater_
.UpdateCommandEnabled(IDC_VIEW_SOURCE
,
1021 CanViewSource(browser_
));
1022 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
,
1023 CanEmailPageLocation(browser_
));
1024 if (browser_
->is_devtools())
1025 command_updater_
.UpdateCommandEnabled(IDC_OPEN_FILE
, false);
1027 // Changing the encoding is not possible on Chrome-internal webpages.
1028 NavigationController
& nc
= current_web_contents
->GetController();
1029 bool is_chrome_internal
= HasInternalURL(nc
.GetActiveEntry()) ||
1030 current_web_contents
->ShowingInterstitialPage();
1031 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MENU
,
1032 !is_chrome_internal
&& current_web_contents
->IsSavable());
1034 // Show various bits of UI
1035 // TODO(pinkerton): Disable app-mode in the model until we implement it
1036 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
1037 #if !defined(OS_MACOSX)
1038 command_updater_
.UpdateCommandEnabled(
1039 IDC_CREATE_SHORTCUTS
,
1040 CanCreateApplicationShortcuts(browser_
));
1043 command_updater_
.UpdateCommandEnabled(
1044 IDC_TOGGLE_REQUEST_TABLET_SITE
,
1045 CanRequestTabletSite(current_web_contents
));
1047 UpdateCommandsForContentRestrictionState();
1048 UpdateCommandsForBookmarkEditing();
1049 UpdateCommandsForFind();
1052 void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1053 int restrictions
= GetContentRestrictions(browser_
);
1055 command_updater_
.UpdateCommandEnabled(
1056 IDC_COPY
, !(restrictions
& CONTENT_RESTRICTION_COPY
));
1057 command_updater_
.UpdateCommandEnabled(
1058 IDC_CUT
, !(restrictions
& CONTENT_RESTRICTION_CUT
));
1059 command_updater_
.UpdateCommandEnabled(
1060 IDC_PASTE
, !(restrictions
& CONTENT_RESTRICTION_PASTE
));
1061 UpdateSaveAsState();
1062 UpdatePrintingState();
1065 void BrowserCommandController::UpdateCommandsForDevTools() {
1066 bool dev_tools_enabled
=
1067 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled
);
1068 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS
,
1070 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE
,
1072 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT
,
1074 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE
,
1078 void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1079 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_PAGE
,
1080 CanBookmarkCurrentPage(browser_
));
1081 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS
,
1082 CanBookmarkAllTabs(browser_
));
1083 command_updater_
.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN
,
1087 void BrowserCommandController::UpdateCommandsForBookmarkBar() {
1088 command_updater_
.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR
,
1089 browser_defaults::bookmarks_enabled
&&
1090 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar
) &&
1094 void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1095 UpdateSaveAsState();
1096 UpdateOpenFileState(&command_updater_
);
1099 void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1100 WindowState window_state
= WINDOW_STATE_NOT_FULLSCREEN
;
1101 if (window() && window()->IsFullscreen()) {
1102 window_state
= WINDOW_STATE_FULLSCREEN
;
1104 if (window()->IsInMetroSnapMode())
1105 window_state
= WINDOW_STATE_METRO_SNAP
;
1108 bool show_main_ui
= IsShowingMainUI();
1109 bool main_not_fullscreen
=
1110 show_main_ui
&& window_state
== WINDOW_STATE_NOT_FULLSCREEN
;
1112 // Navigation commands
1113 command_updater_
.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL
, show_main_ui
);
1115 // Window management commands
1116 command_updater_
.UpdateCommandEnabled(
1118 !browser_
->is_type_tabbed() &&
1119 window_state
== WINDOW_STATE_NOT_FULLSCREEN
);
1121 // Focus various bits of UI
1122 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR
, show_main_ui
);
1123 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_LOCATION
, show_main_ui
);
1124 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_SEARCH
, show_main_ui
);
1125 command_updater_
.UpdateCommandEnabled(
1126 IDC_FOCUS_MENU_BAR
, main_not_fullscreen
);
1127 command_updater_
.UpdateCommandEnabled(
1128 IDC_FOCUS_NEXT_PANE
, main_not_fullscreen
);
1129 command_updater_
.UpdateCommandEnabled(
1130 IDC_FOCUS_PREVIOUS_PANE
, main_not_fullscreen
);
1131 command_updater_
.UpdateCommandEnabled(
1132 IDC_FOCUS_BOOKMARKS
, main_not_fullscreen
);
1133 command_updater_
.UpdateCommandEnabled(
1134 IDC_FOCUS_INFOBARS
, main_not_fullscreen
);
1136 // Show various bits of UI
1137 command_updater_
.UpdateCommandEnabled(IDC_DEVELOPER_MENU
, show_main_ui
);
1138 command_updater_
.UpdateCommandEnabled(IDC_FEEDBACK
, show_main_ui
);
1139 UpdateShowSyncState(show_main_ui
);
1141 // Settings page/subpages are forced to open in normal mode. We disable these
1142 // commands when incognito is forced.
1143 const bool options_enabled
= show_main_ui
&&
1144 IncognitoModePrefs::GetAvailability(
1145 profile()->GetPrefs()) != IncognitoModePrefs::FORCED
;
1146 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
, options_enabled
);
1147 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, options_enabled
);
1149 command_updater_
.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES
, show_main_ui
);
1150 command_updater_
.UpdateCommandEnabled(IDC_VIEW_PASSWORDS
, show_main_ui
);
1151 command_updater_
.UpdateCommandEnabled(IDC_ABOUT
, show_main_ui
);
1152 command_updater_
.UpdateCommandEnabled(IDC_SHOW_APP_MENU
, show_main_ui
);
1153 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC)
1154 command_updater_
.UpdateCommandEnabled(IDC_PROFILING_ENABLED
, show_main_ui
);
1157 // Disable explicit fullscreen toggling when in metro snap mode.
1158 bool fullscreen_enabled
= window_state
!= WINDOW_STATE_METRO_SNAP
;
1159 #if defined(OS_MACOSX)
1160 // The Mac implementation doesn't support switching to fullscreen while
1161 // a tab modal dialog is displayed.
1162 int tab_index
= chrome::IndexOfFirstBlockedTab(browser_
->tab_strip_model());
1163 bool has_blocked_tab
= tab_index
!= browser_
->tab_strip_model()->count();
1164 fullscreen_enabled
&= !has_blocked_tab
;
1166 if (window_state
== WINDOW_STATE_NOT_FULLSCREEN
&&
1167 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed
)) {
1168 // Disable toggling into fullscreen mode if disallowed by pref.
1169 fullscreen_enabled
= false;
1173 command_updater_
.UpdateCommandEnabled(IDC_FULLSCREEN
, fullscreen_enabled
);
1174 command_updater_
.UpdateCommandEnabled(IDC_PRESENTATION_MODE
,
1175 fullscreen_enabled
);
1177 UpdateCommandsForBookmarkBar();
1178 UpdateCommandsForMultipleProfiles();
1181 void BrowserCommandController::UpdateCommandsForMultipleProfiles() {
1182 bool enable
= IsShowingMainUI() &&
1183 !profile()->IsOffTheRecord() &&
1185 AvatarMenuModel::ShouldShowAvatarMenu();
1186 command_updater_
.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU
,
1190 void BrowserCommandController::UpdatePrintingState() {
1191 bool print_enabled
= CanPrint(browser_
);
1192 command_updater_
.UpdateCommandEnabled(IDC_PRINT
, print_enabled
);
1193 command_updater_
.UpdateCommandEnabled(IDC_ADVANCED_PRINT
,
1194 CanAdvancedPrint(browser_
));
1195 command_updater_
.UpdateCommandEnabled(IDC_PRINT_TO_DESTINATION
,
1198 HMODULE metro_module
= base::win::GetMetroModule();
1199 if (metro_module
!= NULL
) {
1200 typedef void (*MetroEnablePrinting
)(BOOL
);
1201 MetroEnablePrinting metro_enable_printing
=
1202 reinterpret_cast<MetroEnablePrinting
>(
1203 ::GetProcAddress(metro_module
, "MetroEnablePrinting"));
1204 if (metro_enable_printing
)
1205 metro_enable_printing(print_enabled
);
1210 void BrowserCommandController::UpdateSaveAsState() {
1211 command_updater_
.UpdateCommandEnabled(IDC_SAVE_PAGE
, CanSavePage(browser_
));
1214 void BrowserCommandController::UpdateShowSyncState(bool show_main_ui
) {
1215 command_updater_
.UpdateCommandEnabled(
1216 IDC_SHOW_SYNC_SETUP
, show_main_ui
&& pref_signin_allowed_
.GetValue());
1220 void BrowserCommandController::UpdateOpenFileState(
1221 CommandUpdater
* command_updater
) {
1222 bool enabled
= true;
1223 PrefService
* local_state
= g_browser_process
->local_state();
1225 enabled
= local_state
->GetBoolean(prefs::kAllowFileSelectionDialogs
);
1227 command_updater
->UpdateCommandEnabled(IDC_OPEN_FILE
, enabled
);
1230 void BrowserCommandController::UpdateReloadStopState(bool is_loading
,
1232 window()->UpdateReloadStopState(is_loading
, force
);
1233 command_updater_
.UpdateCommandEnabled(IDC_STOP
, is_loading
);
1236 void BrowserCommandController::UpdateCommandsForFind() {
1237 TabStripModel
* model
= browser_
->tab_strip_model();
1238 bool enabled
= !model
->IsTabBlocked(model
->active_index()) &&
1239 !browser_
->is_devtools();
1241 command_updater_
.UpdateCommandEnabled(IDC_FIND
, enabled
);
1242 command_updater_
.UpdateCommandEnabled(IDC_FIND_NEXT
, enabled
);
1243 command_updater_
.UpdateCommandEnabled(IDC_FIND_PREVIOUS
, enabled
);
1246 void BrowserCommandController::AddInterstitialObservers(WebContents
* contents
) {
1247 interstitial_observers_
.push_back(new InterstitialObserver(this, contents
));
1250 void BrowserCommandController::RemoveInterstitialObservers(
1251 WebContents
* contents
) {
1252 for (size_t i
= 0; i
< interstitial_observers_
.size(); i
++) {
1253 if (interstitial_observers_
[i
]->web_contents() != contents
)
1256 delete interstitial_observers_
[i
];
1257 interstitial_observers_
.erase(interstitial_observers_
.begin() + i
);
1262 BrowserWindow
* BrowserCommandController::window() {
1263 return browser_
->window();
1266 Profile
* BrowserCommandController::profile() {
1267 return browser_
->profile();
1270 } // namespace chrome