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 "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/defaults.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/prefs/incognito_mode_prefs.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/printing/print_preview_tab_controller.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/sessions/tab_restore_service.h"
17 #include "chrome/browser/sessions/tab_restore_service_factory.h"
18 #include "chrome/browser/shell_integration.h"
19 #include "chrome/browser/sync/profile_sync_service.h"
20 #include "chrome/browser/sync/profile_sync_service_factory.h"
21 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_commands.h"
24 #include "chrome/browser/ui/browser_tabstrip.h"
25 #include "chrome/browser/ui/browser_window.h"
26 #include "chrome/browser/ui/chrome_pages.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents.h"
28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
30 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
31 #include "chrome/common/chrome_notification_types.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/notification_details.h"
38 #include "content/public/browser/notification_source.h"
39 #include "content/public/browser/user_metrics.h"
40 #include "content/public/browser/web_contents.h"
41 #include "content/public/common/content_restriction.h"
42 #include "content/public/common/url_constants.h"
43 #include "ui/base/keycodes/keyboard_codes.h"
46 #include "base/win/metro.h"
50 #include "chrome/browser/ui/ash/ash_util.h"
53 using content::NavigationEntry
;
54 using content::NavigationController
;
55 using content::WebContents
;
59 // Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
60 bool HasInternalURL(const NavigationEntry
* entry
) {
64 // Check the |virtual_url()| first. This catches regular chrome:// URLs
65 // including URLs that were rewritten (such as chrome://bookmarks).
66 if (entry
->GetVirtualURL().SchemeIs(chrome::kChromeUIScheme
))
69 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
70 // view-source: of a chrome:// URL.
71 if (entry
->GetVirtualURL().SchemeIs(chrome::kViewSourceScheme
))
72 return entry
->GetURL().SchemeIs(chrome::kChromeUIScheme
);
78 // Windows 8 specific helper class to manage DefaultBrowserWorker. It does the
79 // following asynchronous actions in order:
80 // 1- Check that chrome is the default browser
81 // 2- If we are the default, restart chrome in metro and exit
82 // 3- If not the default browser show the 'select default browser' system dialog
83 // 4- When dialog dismisses check again who got made the default
84 // 5- If we are the default then restart chrome in metro and exit
85 // 6- If we are not the default exit.
87 // Note: this class deletes itself.
88 class SwichToMetroUIHandler
89 : public ShellIntegration::DefaultWebClientObserver
{
91 SwichToMetroUIHandler()
92 : ALLOW_THIS_IN_INITIALIZER_LIST(default_browser_worker_(
93 new ShellIntegration::DefaultBrowserWorker(this))),
95 default_browser_worker_
->StartCheckIsDefault();
98 virtual ~SwichToMetroUIHandler() {
99 default_browser_worker_
->ObserverDestroyed();
103 virtual void SetDefaultWebClientUIState(
104 ShellIntegration::DefaultWebClientUIState state
) OVERRIDE
{
106 case ShellIntegration::STATE_PROCESSING
:
108 case ShellIntegration::STATE_UNKNOWN
:
110 case ShellIntegration::STATE_IS_DEFAULT
:
111 browser::AttemptRestartWithModeSwitch();
113 case ShellIntegration::STATE_NOT_DEFAULT
:
115 default_browser_worker_
->StartSetAsDefault();
125 virtual void OnSetAsDefaultConcluded(bool success
) OVERRIDE
{
130 first_check_
= false;
131 default_browser_worker_
->StartCheckIsDefault();
134 virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE
{
138 scoped_refptr
<ShellIntegration::DefaultBrowserWorker
> default_browser_worker_
;
141 DISALLOW_COPY_AND_ASSIGN(SwichToMetroUIHandler
);
143 #endif // defined(OS_WIN)
149 ///////////////////////////////////////////////////////////////////////////////
150 // BrowserCommandController, public:
152 BrowserCommandController::BrowserCommandController(Browser
* browser
)
154 ALLOW_THIS_IN_INITIALIZER_LIST(command_updater_(this)),
155 block_command_execution_(false),
156 last_blocked_command_id_(-1),
157 last_blocked_command_disposition_(CURRENT_TAB
) {
158 browser_
->tab_strip_model()->AddObserver(this);
159 PrefService
* local_state
= g_browser_process
->local_state();
161 local_pref_registrar_
.Init(local_state
);
162 local_pref_registrar_
.Add(prefs::kAllowFileSelectionDialogs
, this);
163 local_pref_registrar_
.Add(prefs::kInManagedMode
, this);
166 profile_pref_registrar_
.Init(profile()->GetPrefs());
167 profile_pref_registrar_
.Add(prefs::kDevToolsDisabled
, this);
168 profile_pref_registrar_
.Add(prefs::kEditBookmarksEnabled
, this);
169 profile_pref_registrar_
.Add(prefs::kShowBookmarkBar
, this);
170 profile_pref_registrar_
.Add(prefs::kIncognitoModeAvailability
, this);
171 profile_pref_registrar_
.Add(prefs::kPrintingEnabled
, this);
175 TabRestoreService
* tab_restore_service
=
176 TabRestoreServiceFactory::GetForProfile(profile());
177 if (tab_restore_service
) {
178 tab_restore_service
->AddObserver(this);
179 TabRestoreServiceChanged(tab_restore_service
);
182 ProfileSyncService
* service
=
183 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
185 service
->AddObserver(this);
188 BrowserCommandController::~BrowserCommandController() {
189 ProfileSyncService
* service
=
190 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
192 service
->RemoveObserver(this);
194 // TabRestoreService may have been shutdown by the time we get here. Don't
195 // trigger creating it.
196 TabRestoreService
* tab_restore_service
=
197 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
198 if (tab_restore_service
)
199 tab_restore_service
->RemoveObserver(this);
200 profile_pref_registrar_
.RemoveAll();
201 local_pref_registrar_
.RemoveAll();
202 browser_
->tab_strip_model()->RemoveObserver(this);
205 bool BrowserCommandController::IsReservedCommandOrKey(
207 const content::NativeWebKeyboardEvent
& event
) {
208 // In Apps mode, no keys are reserved.
209 if (browser_
->is_app())
212 #if defined(OS_CHROMEOS)
213 // On Chrome OS, the top row of keys are mapped to F1-F10. We don't want web
214 // pages to be able to change the behavior of these keys. Ash handles F4 and
215 // up; this leaves us needing to reserve F1-F3 here.
216 ui::KeyboardCode key_code
=
217 static_cast<ui::KeyboardCode
>(event
.windowsKeyCode
);
218 if ((key_code
== ui::VKEY_F1
&& command_id
== IDC_BACK
) ||
219 (key_code
== ui::VKEY_F2
&& command_id
== IDC_FORWARD
) ||
220 (key_code
== ui::VKEY_F3
&& command_id
== IDC_RELOAD
)) {
225 if (window()->IsFullscreen() && command_id
== IDC_FULLSCREEN
)
227 return command_id
== IDC_CLOSE_TAB
||
228 command_id
== IDC_CLOSE_WINDOW
||
229 command_id
== IDC_NEW_INCOGNITO_WINDOW
||
230 command_id
== IDC_NEW_TAB
||
231 command_id
== IDC_NEW_WINDOW
||
232 command_id
== IDC_RESTORE_TAB
||
233 command_id
== IDC_SELECT_NEXT_TAB
||
234 command_id
== IDC_SELECT_PREVIOUS_TAB
||
235 command_id
== IDC_TABPOSE
||
236 command_id
== IDC_EXIT
;
239 void BrowserCommandController::SetBlockCommandExecution(bool block
) {
240 block_command_execution_
= block
;
242 last_blocked_command_id_
= -1;
243 last_blocked_command_disposition_
= CURRENT_TAB
;
247 int BrowserCommandController::GetLastBlockedCommand(
248 WindowOpenDisposition
* disposition
) {
250 *disposition
= last_blocked_command_disposition_
;
251 return last_blocked_command_id_
;
254 void BrowserCommandController::TabStateChanged() {
255 UpdateCommandsForTabState();
258 void BrowserCommandController::ContentRestrictionsChanged() {
259 UpdateCommandsForContentRestrictionState();
262 void BrowserCommandController::FullscreenStateChanged() {
263 FullScreenMode fullscreen_mode
= FULLSCREEN_DISABLED
;
264 if (window()->IsFullscreen()) {
266 fullscreen_mode
= window()->IsInMetroSnapMode() ? FULLSCREEN_METRO_SNAP
:
269 fullscreen_mode
= FULLSCREEN_NORMAL
;
272 UpdateCommandsForFullscreenMode(fullscreen_mode
);
275 void BrowserCommandController::PrintingStateChanged() {
276 UpdatePrintingState();
279 void BrowserCommandController::LoadingStateChanged(bool is_loading
,
281 UpdateReloadStopState(is_loading
, force
);
284 ////////////////////////////////////////////////////////////////////////////////
285 // BrowserCommandController,
286 // CommandUpdater::CommandUpdaterDelegate implementation:
288 void BrowserCommandController::ExecuteCommandWithDisposition(
289 int id
, WindowOpenDisposition disposition
) {
290 // No commands are enabled if there is not yet any selected tab.
291 // TODO(pkasting): It seems like we should not need this, because either
292 // most/all commands should not have been enabled yet anyway or the ones that
293 // are enabled should be global, or safe themselves against having no selected
294 // tab. However, Ben says he tried removing this before and got lots of
295 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
296 // window construction. This probably could use closer examination someday.
297 if (!chrome::GetActiveTabContents(browser_
))
300 DCHECK(command_updater_
.IsCommandEnabled(id
)) << "Invalid/disabled command "
303 // If command execution is blocked then just record the command and return.
304 if (block_command_execution_
) {
305 // We actually only allow no more than one blocked command, otherwise some
306 // commands maybe lost.
307 DCHECK_EQ(last_blocked_command_id_
, -1);
308 last_blocked_command_id_
= id
;
309 last_blocked_command_disposition_
= disposition
;
313 // The order of commands in this switch statement must match the function
314 // declaration order in browser.h!
316 // Navigation commands
318 GoBack(browser_
, disposition
);
321 GoForward(browser_
, disposition
);
324 Reload(browser_
, disposition
);
326 case IDC_RELOAD_CLEARING_CACHE
:
327 ClearCache(browser_
);
329 case IDC_RELOAD_IGNORING_CACHE
:
330 ReloadIgnoringCache(browser_
, disposition
);
333 Home(browser_
, disposition
);
335 case IDC_OPEN_CURRENT_URL
:
336 OpenCurrentURL(browser_
);
342 // Window management commands
346 case IDC_NEW_INCOGNITO_WINDOW
:
347 NewIncognitoWindow(browser_
);
349 case IDC_CLOSE_WINDOW
:
350 CloseWindow(browser_
);
358 case IDC_SELECT_NEXT_TAB
:
359 SelectNextTab(browser_
);
361 case IDC_SELECT_PREVIOUS_TAB
:
362 SelectPreviousTab(browser_
);
365 OpenTabpose(browser_
);
367 case IDC_MOVE_TAB_NEXT
:
368 MoveTabNext(browser_
);
370 case IDC_MOVE_TAB_PREVIOUS
:
371 MoveTabPrevious(browser_
);
373 case IDC_SELECT_TAB_0
:
374 case IDC_SELECT_TAB_1
:
375 case IDC_SELECT_TAB_2
:
376 case IDC_SELECT_TAB_3
:
377 case IDC_SELECT_TAB_4
:
378 case IDC_SELECT_TAB_5
:
379 case IDC_SELECT_TAB_6
:
380 case IDC_SELECT_TAB_7
:
381 SelectNumberedTab(browser_
, id
- IDC_SELECT_TAB_0
);
383 case IDC_SELECT_LAST_TAB
:
384 SelectLastTab(browser_
);
386 case IDC_DUPLICATE_TAB
:
387 DuplicateTab(browser_
);
389 case IDC_RESTORE_TAB
:
390 RestoreTab(browser_
);
392 case IDC_SHOW_AS_TAB
:
393 ConvertPopupToTabbedBrowser(browser_
);
396 chrome::ToggleFullscreenMode(browser_
);
400 case IDC_TOGGLE_ASH_DESKTOP
:
401 chrome::ToggleAshDesktop();
406 // Windows 8 specific commands.
407 case IDC_METRO_SNAP_ENABLE
:
408 browser_
->SetMetroSnapMode(true);
410 case IDC_METRO_SNAP_DISABLE
:
411 browser_
->SetMetroSnapMode(false);
413 case IDC_WIN8_DESKTOP_RESTART
:
414 browser::AttemptRestartWithModeSwitch();
415 content::RecordAction(content::UserMetricsAction("Win8DesktopRestart"));
417 case IDC_WIN8_METRO_RESTART
:
418 new SwichToMetroUIHandler
;
419 content::RecordAction(content::UserMetricsAction("Win8MetroRestart"));
423 #if defined(OS_MACOSX)
424 case IDC_PRESENTATION_MODE
:
425 browser_
->TogglePresentationMode();
432 // Page-related commands
436 case IDC_BOOKMARK_PAGE
:
437 BookmarkCurrentPage(browser_
);
439 case IDC_BOOKMARK_PAGE_FROM_STAR
:
440 BookmarkCurrentPageFromStar(browser_
);
442 case IDC_PIN_TO_START_SCREEN
:
443 TogglePagePinnedToStartScreen(browser_
);
445 case IDC_BOOKMARK_ALL_TABS
:
446 BookmarkAllTabs(browser_
);
448 case IDC_VIEW_SOURCE
:
449 ViewSelectedSource(browser_
);
451 case IDC_EMAIL_PAGE_LOCATION
:
452 EmailPageLocation(browser_
);
457 case IDC_ADVANCED_PRINT
:
458 AdvancedPrint(browser_
);
460 case IDC_PRINT_TO_DESTINATION
:
461 PrintToDestination(browser_
);
463 case IDC_CHROME_TO_MOBILE_PAGE
:
464 ShowChromeToMobileBubble(browser_
);
466 case IDC_ENCODING_AUTO_DETECT
:
467 browser_
->ToggleEncodingAutoDetect();
469 case IDC_ENCODING_UTF8
:
470 case IDC_ENCODING_UTF16LE
:
471 case IDC_ENCODING_ISO88591
:
472 case IDC_ENCODING_WINDOWS1252
:
473 case IDC_ENCODING_GBK
:
474 case IDC_ENCODING_GB18030
:
475 case IDC_ENCODING_BIG5HKSCS
:
476 case IDC_ENCODING_BIG5
:
477 case IDC_ENCODING_KOREAN
:
478 case IDC_ENCODING_SHIFTJIS
:
479 case IDC_ENCODING_ISO2022JP
:
480 case IDC_ENCODING_EUCJP
:
481 case IDC_ENCODING_THAI
:
482 case IDC_ENCODING_ISO885915
:
483 case IDC_ENCODING_MACINTOSH
:
484 case IDC_ENCODING_ISO88592
:
485 case IDC_ENCODING_WINDOWS1250
:
486 case IDC_ENCODING_ISO88595
:
487 case IDC_ENCODING_WINDOWS1251
:
488 case IDC_ENCODING_KOI8R
:
489 case IDC_ENCODING_KOI8U
:
490 case IDC_ENCODING_ISO88597
:
491 case IDC_ENCODING_WINDOWS1253
:
492 case IDC_ENCODING_ISO88594
:
493 case IDC_ENCODING_ISO885913
:
494 case IDC_ENCODING_WINDOWS1257
:
495 case IDC_ENCODING_ISO88593
:
496 case IDC_ENCODING_ISO885910
:
497 case IDC_ENCODING_ISO885914
:
498 case IDC_ENCODING_ISO885916
:
499 case IDC_ENCODING_WINDOWS1254
:
500 case IDC_ENCODING_ISO88596
:
501 case IDC_ENCODING_WINDOWS1256
:
502 case IDC_ENCODING_ISO88598
:
503 case IDC_ENCODING_ISO88598I
:
504 case IDC_ENCODING_WINDOWS1255
:
505 case IDC_ENCODING_WINDOWS1258
:
506 browser_
->OverrideEncoding(id
);
509 // Clipboard commands
527 case IDC_FIND_PREVIOUS
:
528 FindPrevious(browser_
);
533 Zoom(browser_
, content::PAGE_ZOOM_IN
);
535 case IDC_ZOOM_NORMAL
:
536 Zoom(browser_
, content::PAGE_ZOOM_RESET
);
539 Zoom(browser_
, content::PAGE_ZOOM_OUT
);
542 // Focus various bits of UI
543 case IDC_FOCUS_TOOLBAR
:
544 FocusToolbar(browser_
);
546 case IDC_FOCUS_LOCATION
:
547 FocusLocationBar(browser_
);
549 case IDC_FOCUS_SEARCH
:
550 FocusSearch(browser_
);
552 case IDC_FOCUS_MENU_BAR
:
553 FocusAppMenu(browser_
);
555 case IDC_FOCUS_BOOKMARKS
:
556 FocusBookmarksToolbar(browser_
);
558 case IDC_FOCUS_NEXT_PANE
:
559 FocusNextPane(browser_
);
561 case IDC_FOCUS_PREVIOUS_PANE
:
562 FocusPreviousPane(browser_
);
565 // Show various bits of UI
567 browser_
->OpenFile();
569 case IDC_CREATE_SHORTCUTS
:
570 CreateApplicationShortcuts(browser_
);
573 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_SHOW
);
575 case IDC_DEV_TOOLS_CONSOLE
:
576 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE
);
578 case IDC_DEV_TOOLS_INSPECT
:
579 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_INSPECT
);
581 case IDC_DEV_TOOLS_TOGGLE
:
582 ToggleDevToolsWindow(browser_
, DEVTOOLS_TOGGLE_ACTION_TOGGLE
);
584 case IDC_TASK_MANAGER
:
585 OpenTaskManager(browser_
, false);
587 case IDC_VIEW_BACKGROUND_PAGES
:
588 OpenTaskManager(browser_
, true);
591 OpenFeedbackDialog(browser_
);
594 case IDC_SHOW_BOOKMARK_BAR
:
595 ToggleBookmarkBar(browser_
);
597 case IDC_PROFILING_ENABLED
:
601 case IDC_SHOW_BOOKMARK_MANAGER
:
602 ShowBookmarkManager(browser_
);
604 case IDC_SHOW_APP_MENU
:
605 ShowAppMenu(browser_
);
607 case IDC_SHOW_AVATAR_MENU
:
608 ShowAvatarMenu(browser_
);
610 case IDC_SHOW_HISTORY
:
611 ShowHistory(browser_
);
613 case IDC_SHOW_DOWNLOADS
:
614 ShowDownloads(browser_
);
616 case IDC_MANAGE_EXTENSIONS
:
617 ShowExtensions(browser_
);
620 ShowSettings(browser_
);
622 case IDC_EDIT_SEARCH_ENGINES
:
623 ShowSearchEngineSettings(browser_
);
625 case IDC_VIEW_PASSWORDS
:
626 ShowPasswordManager(browser_
);
628 case IDC_CLEAR_BROWSING_DATA
:
629 ShowClearBrowsingDataDialog(browser_
);
631 case IDC_IMPORT_SETTINGS
:
632 ShowImportDialog(browser_
);
634 case IDC_TOGGLE_REQUEST_TABLET_SITE
:
635 ToggleRequestTabletSite(browser_
);
638 ShowAboutChrome(browser_
);
640 case IDC_UPGRADE_DIALOG
:
641 OpenUpdateChromeDialog(browser_
);
643 case IDC_VIEW_INCOMPATIBILITIES
:
644 ShowConflicts(browser_
);
646 case IDC_HELP_PAGE_VIA_KEYBOARD
:
647 ShowHelp(browser_
, HELP_SOURCE_KEYBOARD
);
649 case IDC_HELP_PAGE_VIA_MENU
:
650 ShowHelp(browser_
, HELP_SOURCE_MENU
);
652 case IDC_SHOW_SYNC_SETUP
:
653 ShowSyncSetup(browser_
, SyncPromoUI::SOURCE_MENU
);
655 case IDC_TOGGLE_SPEECH_INPUT
:
656 ToggleSpeechInput(browser_
);
660 LOG(WARNING
) << "Received Unimplemented Command: " << id
;
665 ////////////////////////////////////////////////////////////////////////////////
666 // BrowserCommandController, content::NotificationObserver implementation:
668 void BrowserCommandController::Observe(
670 const content::NotificationSource
& source
,
671 const content::NotificationDetails
& details
) {
673 case content::NOTIFICATION_INTERSTITIAL_ATTACHED
:
674 UpdateCommandsForTabState();
677 case content::NOTIFICATION_INTERSTITIAL_DETACHED
:
678 UpdateCommandsForTabState();
682 NOTREACHED() << "Got a notification we didn't register for.";
686 ////////////////////////////////////////////////////////////////////////////////
687 // PrefObserver implementation:
689 void BrowserCommandController::OnPreferenceChanged(
690 PrefServiceBase
* service
,
691 const std::string
& pref_name
) {
692 if (pref_name
== prefs::kPrintingEnabled
) {
693 UpdatePrintingState();
694 } else if (pref_name
== prefs::kIncognitoModeAvailability
) {
695 UpdateCommandsForIncognitoAvailability();
696 } else if (pref_name
== prefs::kDevToolsDisabled
) {
697 UpdateCommandsForDevTools();
698 } else if (pref_name
== prefs::kEditBookmarksEnabled
) {
699 UpdateCommandsForBookmarkEditing();
700 } else if (pref_name
== prefs::kShowBookmarkBar
) {
701 UpdateCommandsForBookmarkBar();
702 } else if (pref_name
== prefs::kAllowFileSelectionDialogs
) {
704 UpdateOpenFileState();
705 } else if (pref_name
== prefs::kInManagedMode
) {
706 UpdateCommandsForMultipleProfiles();
712 ////////////////////////////////////////////////////////////////////////////////
713 // BrowserCommandController, TabStripModelObserver implementation:
715 void BrowserCommandController::TabInsertedAt(WebContents
* contents
,
718 AddInterstitialObservers(contents
);
721 void BrowserCommandController::TabDetachedAt(WebContents
* contents
, int index
) {
722 RemoveInterstitialObservers(contents
);
725 void BrowserCommandController::TabReplacedAt(TabStripModel
* tab_strip_model
,
726 WebContents
* old_contents
,
727 WebContents
* new_contents
,
729 RemoveInterstitialObservers(old_contents
);
730 AddInterstitialObservers(new_contents
);
733 ////////////////////////////////////////////////////////////////////////////////
734 // BrowserCommandController, TabRestoreServiceObserver implementation:
736 void BrowserCommandController::TabRestoreServiceChanged(
737 TabRestoreService
* service
) {
738 command_updater_
.UpdateCommandEnabled(IDC_RESTORE_TAB
,
739 CanRestoreTab(browser_
));
742 void BrowserCommandController::TabRestoreServiceDestroyed(
743 TabRestoreService
* service
) {
744 service
->RemoveObserver(this);
747 ////////////////////////////////////////////////////////////////////////////////
748 // BrowserCommandController, ProfileSyncServiceObserver implementation:
750 void BrowserCommandController::OnStateChanged() {
751 DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
753 // For unit tests, we don't have a window.
756 const bool show_main_ui
= IsShowingMainUI(window()->IsFullscreen());
757 command_updater_
.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP
,
758 show_main_ui
&& profile()->GetOriginalProfile()->IsSyncAccessible());
761 ////////////////////////////////////////////////////////////////////////////////
762 // BrowserCommandController, private:
764 bool BrowserCommandController::IsShowingMainUI(bool is_fullscreen
) {
765 #if !defined(OS_MACOSX)
766 return browser_
->is_type_tabbed() && !is_fullscreen
;
768 return browser_
->is_type_tabbed();
772 void BrowserCommandController::InitCommandState() {
773 // All browser commands whose state isn't set automagically some other way
774 // (like Back & Forward with initial page load) must have their state
775 // initialized here, otherwise they will be forever disabled.
777 // Navigation commands
778 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, true);
779 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
, true);
780 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
, true);
782 // Window management commands
783 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_WINDOW
, true);
784 command_updater_
.UpdateCommandEnabled(IDC_NEW_TAB
, true);
785 command_updater_
.UpdateCommandEnabled(IDC_CLOSE_TAB
, true);
786 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
, true);
787 command_updater_
.UpdateCommandEnabled(IDC_RESTORE_TAB
, false);
788 command_updater_
.UpdateCommandEnabled(IDC_EXIT
, true);
789 command_updater_
.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE
, true);
791 if (chrome::HOST_DESKTOP_TYPE_NATIVE
!= chrome::HOST_DESKTOP_TYPE_ASH
)
792 command_updater_
.UpdateCommandEnabled(IDC_TOGGLE_ASH_DESKTOP
, true);
795 // Page-related commands
796 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
, true);
797 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT
, true);
798 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF8
, true);
799 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_UTF16LE
, true);
800 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88591
, true);
801 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252
, true);
802 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GBK
, true);
803 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_GB18030
, true);
804 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS
, true);
805 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_BIG5
, true);
806 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_THAI
, true);
807 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOREAN
, true);
808 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS
, true);
809 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP
, true);
810 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_EUCJP
, true);
811 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885915
, true);
812 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH
, true);
813 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88592
, true);
814 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250
, true);
815 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88595
, true);
816 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251
, true);
817 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8R
, true);
818 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_KOI8U
, true);
819 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88597
, true);
820 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253
, true);
821 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88594
, true);
822 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885913
, true);
823 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257
, true);
824 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88593
, true);
825 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885910
, true);
826 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885914
, true);
827 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO885916
, true);
828 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254
, true);
829 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88596
, true);
830 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256
, true);
831 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598
, true);
832 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_ISO88598I
, true);
833 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255
, true);
834 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258
, true);
837 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MENU
, true);
838 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_PLUS
, true);
839 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_NORMAL
, true);
840 command_updater_
.UpdateCommandEnabled(IDC_ZOOM_MINUS
, true);
842 // Show various bits of UI
843 UpdateOpenFileState();
844 command_updater_
.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS
, false);
845 UpdateCommandsForDevTools();
846 command_updater_
.UpdateCommandEnabled(IDC_TASK_MANAGER
, CanOpenTaskManager());
847 command_updater_
.UpdateCommandEnabled(IDC_SHOW_HISTORY
,
848 !Profile::IsGuestSession());
849 command_updater_
.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS
, true);
850 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD
, true);
851 command_updater_
.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU
, true);
852 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARKS_MENU
,
853 !Profile::IsGuestSession());
854 command_updater_
.UpdateCommandEnabled(IDC_RECENT_TABS_MENU
,
855 !Profile::IsGuestSession() &&
856 !profile()->IsOffTheRecord());
858 command_updater_
.UpdateCommandEnabled(
859 IDC_SHOW_SYNC_SETUP
, profile()->GetOriginalProfile()->IsSyncAccessible());
861 // Initialize other commands based on the window type.
862 bool normal_window
= browser_
->is_type_tabbed();
864 // Navigation commands
865 command_updater_
.UpdateCommandEnabled(IDC_HOME
, normal_window
);
867 // Window management commands
868 command_updater_
.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB
, normal_window
);
869 command_updater_
.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB
,
871 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT
, normal_window
);
872 command_updater_
.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS
, normal_window
);
873 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_0
, normal_window
);
874 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_1
, normal_window
);
875 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_2
, normal_window
);
876 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_3
, normal_window
);
877 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_4
, normal_window
);
878 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_5
, normal_window
);
879 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_6
, normal_window
);
880 command_updater_
.UpdateCommandEnabled(IDC_SELECT_TAB_7
, normal_window
);
881 command_updater_
.UpdateCommandEnabled(IDC_SELECT_LAST_TAB
, normal_window
);
883 const bool metro_mode
= base::win::IsMetroProcess();
884 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE
, metro_mode
);
885 command_updater_
.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE
, metro_mode
);
886 int restart_mode
= metro_mode
?
887 IDC_WIN8_DESKTOP_RESTART
: IDC_WIN8_METRO_RESTART
;
888 command_updater_
.UpdateCommandEnabled(restart_mode
, normal_window
);
890 command_updater_
.UpdateCommandEnabled(IDC_TABPOSE
, normal_window
);
893 command_updater_
.UpdateCommandEnabled(IDC_FIND
, !browser_
->is_devtools());
894 command_updater_
.UpdateCommandEnabled(IDC_FIND_NEXT
,
895 !browser_
->is_devtools());
896 command_updater_
.UpdateCommandEnabled(IDC_FIND_PREVIOUS
,
897 !browser_
->is_devtools());
899 // Show various bits of UI
900 command_updater_
.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA
, normal_window
);
902 // The upgrade entry and the view incompatibility entry should always be
903 // enabled. Whether they are visible is a separate matter determined on menu
905 command_updater_
.UpdateCommandEnabled(IDC_UPGRADE_DIALOG
, true);
906 command_updater_
.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES
, true);
908 // View Background Pages entry is always enabled, but is hidden if there are
909 // no background pages.
910 command_updater_
.UpdateCommandEnabled(IDC_VIEW_BACKGROUND_PAGES
, true);
912 // Toggle speech input
913 command_updater_
.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT
, true);
915 // Initialize other commands whose state changes based on fullscreen mode.
916 UpdateCommandsForFullscreenMode(FULLSCREEN_DISABLED
);
918 UpdateCommandsForContentRestrictionState();
920 UpdateCommandsForBookmarkEditing();
922 UpdateCommandsForIncognitoAvailability();
925 void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
926 IncognitoModePrefs::Availability incognito_availability
=
927 IncognitoModePrefs::GetAvailability(profile()->GetPrefs());
928 command_updater_
.UpdateCommandEnabled(
930 incognito_availability
!= IncognitoModePrefs::FORCED
);
931 command_updater_
.UpdateCommandEnabled(
932 IDC_NEW_INCOGNITO_WINDOW
,
933 incognito_availability
!= IncognitoModePrefs::DISABLED
);
935 // Bookmark manager and settings page/subpages are forced to open in normal
936 // mode. For this reason we disable these commands when incognito is forced.
937 const bool command_enabled
=
938 incognito_availability
!= IncognitoModePrefs::FORCED
;
939 command_updater_
.UpdateCommandEnabled(
940 IDC_SHOW_BOOKMARK_MANAGER
,
941 browser_defaults::bookmarks_enabled
&& command_enabled
);
942 ExtensionService
* extension_service
= profile()->GetExtensionService();
943 bool enable_extensions
=
944 extension_service
&& extension_service
->extensions_enabled();
945 command_updater_
.UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS
,
946 enable_extensions
&& command_enabled
);
948 const bool show_main_ui
=
949 IsShowingMainUI(window() && window()->IsFullscreen());
950 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
,
951 show_main_ui
&& command_enabled
);
952 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
,
953 show_main_ui
&& command_enabled
);
956 void BrowserCommandController::UpdateCommandsForTabState() {
957 WebContents
* current_web_contents
= chrome::GetActiveWebContents(browser_
);
958 if (!current_web_contents
) // May be NULL during tab restore.
961 // Navigation commands
962 command_updater_
.UpdateCommandEnabled(IDC_BACK
, CanGoBack(browser_
));
963 command_updater_
.UpdateCommandEnabled(IDC_FORWARD
, CanGoForward(browser_
));
964 command_updater_
.UpdateCommandEnabled(IDC_RELOAD
, CanReload(browser_
));
965 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE
,
966 CanReload(browser_
));
967 command_updater_
.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE
,
968 CanReload(browser_
));
970 // Window management commands
971 command_updater_
.UpdateCommandEnabled(IDC_DUPLICATE_TAB
,
972 !browser_
->is_app() && CanDuplicateTab(browser_
));
974 // Page-related commands
975 window()->SetStarredState(
976 BookmarkTabHelper::FromWebContents(current_web_contents
)->is_starred());
977 window()->ZoomChangedForActiveTab(false);
978 command_updater_
.UpdateCommandEnabled(IDC_VIEW_SOURCE
,
979 CanViewSource(browser_
));
980 command_updater_
.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION
,
981 CanEmailPageLocation(browser_
));
982 if (browser_
->is_devtools())
983 command_updater_
.UpdateCommandEnabled(IDC_OPEN_FILE
, false);
985 // Changing the encoding is not possible on Chrome-internal webpages.
986 NavigationController
& nc
= current_web_contents
->GetController();
987 bool is_chrome_internal
= HasInternalURL(nc
.GetActiveEntry()) ||
988 current_web_contents
->ShowingInterstitialPage();
989 command_updater_
.UpdateCommandEnabled(IDC_ENCODING_MENU
,
990 !is_chrome_internal
&& current_web_contents
->IsSavable());
992 // Show various bits of UI
993 // TODO(pinkerton): Disable app-mode in the model until we implement it
994 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
995 #if !defined(OS_MACOSX)
996 command_updater_
.UpdateCommandEnabled(
997 IDC_CREATE_SHORTCUTS
,
998 CanCreateApplicationShortcuts(browser_
));
1001 command_updater_
.UpdateCommandEnabled(
1002 IDC_TOGGLE_REQUEST_TABLET_SITE
,
1003 CanRequestTabletSite(current_web_contents
));
1005 UpdateCommandsForContentRestrictionState();
1006 UpdateCommandsForBookmarkEditing();
1009 void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1010 int restrictions
= GetContentRestrictions(browser_
);
1012 command_updater_
.UpdateCommandEnabled(
1013 IDC_COPY
, !(restrictions
& content::CONTENT_RESTRICTION_COPY
));
1014 command_updater_
.UpdateCommandEnabled(
1015 IDC_CUT
, !(restrictions
& content::CONTENT_RESTRICTION_CUT
));
1016 command_updater_
.UpdateCommandEnabled(
1017 IDC_PASTE
, !(restrictions
& content::CONTENT_RESTRICTION_PASTE
));
1018 UpdateSaveAsState();
1019 UpdatePrintingState();
1022 void BrowserCommandController::UpdateCommandsForDevTools() {
1023 bool dev_tools_enabled
=
1024 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled
);
1025 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS
,
1027 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE
,
1029 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT
,
1031 command_updater_
.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE
,
1035 void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1036 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_PAGE
,
1037 CanBookmarkCurrentPage(browser_
));
1038 command_updater_
.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS
,
1039 CanBookmarkAllTabs(browser_
));
1040 command_updater_
.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN
,
1044 void BrowserCommandController::UpdateCommandsForBookmarkBar() {
1045 const bool show_main_ui
=
1046 IsShowingMainUI(window() && window()->IsFullscreen());
1047 command_updater_
.UpdateCommandEnabled(IDC_SHOW_BOOKMARK_BAR
,
1048 browser_defaults::bookmarks_enabled
&&
1049 !profile()->GetPrefs()->IsManagedPreference(prefs::kShowBookmarkBar
) &&
1053 void BrowserCommandController::UpdateCommandsForFullscreenMode(
1054 FullScreenMode fullscreen_mode
) {
1055 const bool show_main_ui
=
1056 IsShowingMainUI(fullscreen_mode
!= FULLSCREEN_DISABLED
);
1057 bool main_not_fullscreen
= show_main_ui
&&
1058 (fullscreen_mode
== FULLSCREEN_DISABLED
);
1060 // Navigation commands
1061 command_updater_
.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL
, show_main_ui
);
1063 // Window management commands
1064 command_updater_
.UpdateCommandEnabled(
1066 !browser_
->is_type_tabbed() && fullscreen_mode
== FULLSCREEN_DISABLED
);
1068 // Focus various bits of UI
1069 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR
, show_main_ui
);
1070 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_LOCATION
, show_main_ui
);
1071 command_updater_
.UpdateCommandEnabled(IDC_FOCUS_SEARCH
, show_main_ui
);
1072 command_updater_
.UpdateCommandEnabled(
1073 IDC_FOCUS_MENU_BAR
, main_not_fullscreen
);
1074 command_updater_
.UpdateCommandEnabled(
1075 IDC_FOCUS_NEXT_PANE
, main_not_fullscreen
);
1076 command_updater_
.UpdateCommandEnabled(
1077 IDC_FOCUS_PREVIOUS_PANE
, main_not_fullscreen
);
1078 command_updater_
.UpdateCommandEnabled(
1079 IDC_FOCUS_BOOKMARKS
, main_not_fullscreen
);
1081 // Show various bits of UI
1082 command_updater_
.UpdateCommandEnabled(IDC_DEVELOPER_MENU
, show_main_ui
);
1083 command_updater_
.UpdateCommandEnabled(IDC_FEEDBACK
, show_main_ui
);
1084 command_updater_
.UpdateCommandEnabled(IDC_SHOW_SYNC_SETUP
,
1085 show_main_ui
&& profile()->GetOriginalProfile()->IsSyncAccessible());
1087 // Settings page/subpages are forced to open in normal mode. We disable these
1088 // commands when incognito is forced.
1089 const bool options_enabled
= show_main_ui
&&
1090 IncognitoModePrefs::GetAvailability(
1091 profile()->GetPrefs()) != IncognitoModePrefs::FORCED
;
1092 command_updater_
.UpdateCommandEnabled(IDC_OPTIONS
, options_enabled
);
1093 command_updater_
.UpdateCommandEnabled(IDC_IMPORT_SETTINGS
, options_enabled
);
1095 command_updater_
.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES
, show_main_ui
);
1096 command_updater_
.UpdateCommandEnabled(IDC_VIEW_PASSWORDS
, show_main_ui
);
1097 command_updater_
.UpdateCommandEnabled(IDC_ABOUT
, show_main_ui
);
1098 command_updater_
.UpdateCommandEnabled(IDC_SHOW_APP_MENU
, show_main_ui
);
1099 #if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC)
1100 command_updater_
.UpdateCommandEnabled(IDC_PROFILING_ENABLED
, show_main_ui
);
1103 // Disable explicit fullscreen toggling when in metro snap mode.
1104 bool fullscreen_enabled
= !browser_
->is_type_panel() &&
1105 !browser_
->is_app() &&
1106 fullscreen_mode
!= FULLSCREEN_METRO_SNAP
;
1107 #if defined(OS_MACOSX)
1108 // The Mac implementation doesn't support switching to fullscreen while
1109 // a tab modal dialog is displayed.
1110 int tabIndex
= chrome::IndexOfFirstBlockedTab(browser_
->tab_strip_model());
1111 bool has_blocked_tab
= tabIndex
!= browser_
->tab_strip_model()->count();
1112 fullscreen_enabled
&= !has_blocked_tab
;
1115 command_updater_
.UpdateCommandEnabled(IDC_FULLSCREEN
, fullscreen_enabled
);
1116 command_updater_
.UpdateCommandEnabled(IDC_PRESENTATION_MODE
,
1117 fullscreen_enabled
);
1119 UpdateCommandsForBookmarkBar();
1120 UpdateCommandsForMultipleProfiles();
1123 void BrowserCommandController::UpdateCommandsForMultipleProfiles() {
1124 bool show_main_ui
= IsShowingMainUI(window() && window()->IsFullscreen());
1125 command_updater_
.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU
,
1127 !profile()->IsOffTheRecord() &&
1128 ProfileManager::IsMultipleProfilesEnabled());
1131 void BrowserCommandController::UpdatePrintingState() {
1132 bool print_enabled
= CanPrint(browser_
);
1133 command_updater_
.UpdateCommandEnabled(IDC_PRINT
, print_enabled
);
1134 command_updater_
.UpdateCommandEnabled(IDC_ADVANCED_PRINT
,
1135 CanAdvancedPrint(browser_
));
1136 command_updater_
.UpdateCommandEnabled(IDC_PRINT_TO_DESTINATION
,
1139 HMODULE metro_module
= base::win::GetMetroModule();
1140 if (metro_module
!= NULL
) {
1141 typedef void (*MetroEnablePrinting
)(BOOL
);
1142 MetroEnablePrinting metro_enable_printing
=
1143 reinterpret_cast<MetroEnablePrinting
>(
1144 ::GetProcAddress(metro_module
, "MetroEnablePrinting"));
1145 if (metro_enable_printing
)
1146 metro_enable_printing(print_enabled
);
1151 void BrowserCommandController::UpdateSaveAsState() {
1152 command_updater_
.UpdateCommandEnabled(IDC_SAVE_PAGE
, CanSavePage(browser_
));
1155 void BrowserCommandController::UpdateOpenFileState() {
1156 bool enabled
= true;
1157 PrefService
* local_state
= g_browser_process
->local_state();
1159 enabled
= local_state
->GetBoolean(prefs::kAllowFileSelectionDialogs
);
1161 command_updater_
.UpdateCommandEnabled(IDC_OPEN_FILE
, enabled
);
1164 void BrowserCommandController::UpdateReloadStopState(bool is_loading
,
1166 window()->UpdateReloadStopState(is_loading
, force
);
1167 command_updater_
.UpdateCommandEnabled(IDC_STOP
, is_loading
);
1170 void BrowserCommandController::AddInterstitialObservers(WebContents
* contents
) {
1171 registrar_
.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED
,
1172 content::Source
<WebContents
>(contents
));
1173 registrar_
.Add(this, content::NOTIFICATION_INTERSTITIAL_DETACHED
,
1174 content::Source
<WebContents
>(contents
));
1177 void BrowserCommandController::RemoveInterstitialObservers(
1178 WebContents
* contents
) {
1179 registrar_
.Remove(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED
,
1180 content::Source
<WebContents
>(contents
));
1181 registrar_
.Remove(this, content::NOTIFICATION_INTERSTITIAL_DETACHED
,
1182 content::Source
<WebContents
>(contents
));
1185 BrowserWindow
* BrowserCommandController::window() {
1186 return browser_
->window();
1189 Profile
* BrowserCommandController::profile() {
1190 return browser_
->profile();
1193 } // namespace chrome