diff options
Diffstat (limited to 'chrome/browser/ui/browser_command_controller.h')
-rw-r--r-- | chrome/browser/ui/browser_command_controller.h | 188 |
1 files changed, 188 insertions, 0 deletions
diff --git a/chrome/browser/ui/browser_command_controller.h b/chrome/browser/ui/browser_command_controller.h new file mode 100644 index 0000000..909e7e7 --- /dev/null +++ b/chrome/browser/ui/browser_command_controller.h @@ -0,0 +1,188 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_ +#define CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_ +#pragma once + +#include "chrome/browser/command_updater.h" +#include "chrome/browser/prefs/pref_change_registrar.h" +#include "chrome/browser/sessions/tab_restore_service_observer.h" +#include "chrome/browser/sync/profile_sync_service_observer.h" +#include "chrome/browser/ui/tabs/tab_strip_model_observer.h" +#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/notification_observer.h" +#include "webkit/glue/window_open_disposition.h" + +class Browser; +class BrowserWindow; +class Profile; +class TabContents; + +namespace content { +struct NativeWebKeyboardEvent; +} + +namespace chrome { + +class BrowserCommandController : public CommandUpdater::CommandUpdaterDelegate, + public content::NotificationObserver, + public TabStripModelObserver, + public TabRestoreServiceObserver, + public ProfileSyncServiceObserver { + public: + explicit BrowserCommandController(Browser* browser); + virtual ~BrowserCommandController(); + + CommandUpdater* command_updater() { return &command_updater_; } + bool block_command_execution() const { return block_command_execution_; } + + // Returns true if |command_id| is a reserved command whose keyboard shortcuts + // should not be sent to the renderer or |event| was triggered by a key that + // we never want to send to the renderer. + bool IsReservedCommandOrKey(int command_id, + const content::NativeWebKeyboardEvent& event); + + // Sets if command execution shall be blocked. If |block| is true then + // following calls to ExecuteCommand() or ExecuteCommandWithDisposition() + // method will not execute the command, and the last blocked command will be + // recorded for retrieval. + void SetBlockCommandExecution(bool block); + + // Gets the last blocked command after calling SetBlockCommandExecution(true). + // Returns the command id or -1 if there is no command blocked. The + // disposition type of the command will be stored in |*disposition| if it's + // not NULL. + int GetLastBlockedCommand(WindowOpenDisposition* disposition); + + // Notifies the controller that state has changed in one of the following + // areas and it should update command states. + void TabStateChanged(); + void ContentRestrictionsChanged(); + void FullscreenStateChanged(); + void PrintingStateChanged(); + void LoadingStateChanged(bool is_loading, bool force); + void SendToMobileStateChanged(bool send_to_mobile_available); + + private: + enum FullScreenMode { + // Not in fullscreen mode. + FULLSCREEN_DISABLED, + + // Fullscreen mode, occupying the whole screen. + FULLSCREEN_NORMAL, + + // Fullscreen mode for metro snap, occupying the full height and 20% of + // the screen width. + FULLSCREEN_METRO_SNAP, + }; + + // Overridden from CommandUpdater::CommandUpdaterDelegate: + virtual void ExecuteCommandWithDisposition( + int id, + WindowOpenDisposition disposition) OVERRIDE; + + // Overridden from content::NotificationObserver: + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) OVERRIDE; + + // Overridden from TabStripModelObserver: + virtual void TabInsertedAt(TabContents* contents, + int index, + bool foreground) OVERRIDE; + virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; + virtual void TabReplacedAt(TabStripModel* tab_strip_model, + TabContents* old_contents, + TabContents* new_contents, + int index) OVERRIDE; + + // Overridden from TabRestoreServiceObserver: + virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE; + virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE; + + // Overridden from ProfileSyncServiceObserver: + virtual void OnStateChanged() OVERRIDE; + + // Returns true if the regular Chrome UI (not the fullscreen one and + // not the single-tab one) is shown. Used for updating window command states + // only. Consider using SupportsWindowFeature if you need the mentioned + // functionality anywhere else. + bool IsShowingMainUI(bool is_fullscreen); + + // Initialize state for all browser commands. + void InitCommandState(); + + // Update commands whose state depends on incognito mode availability. + void UpdateCommandsForIncognitoAvailability(); + + // Update commands whose state depends on the tab's state. + void UpdateCommandsForTabState(); + + // Updates commands when the content's restrictions change. + void UpdateCommandsForContentRestrictionState(); + + // Updates commands for enabling developer tools. + void UpdateCommandsForDevTools(); + + // Updates commands for bookmark editing. + void UpdateCommandsForBookmarkEditing(); + + // Updates commands that affect the bookmark bar. + void UpdateCommandsForBookmarkBar(); + + // Update commands whose state depends on the type of fullscreen mode the + // window is in. + void UpdateCommandsForFullscreenMode(FullScreenMode fullscreen_mode); + + // Update commands whose state depends on whether multiple profiles are + // allowed. + void UpdateCommandsForMultipleProfiles(); + + // Updates the printing command state. + void UpdatePrintingState(); + + // Updates the save-page-as command state. + void UpdateSaveAsState(); + + // Updates the open-file state (Mac Only). + void UpdateOpenFileState(); + + // Ask the Reload/Stop button to change its icon, and update the Stop command + // state. |is_loading| is true if the current WebContents is loading. + // |force| is true if the button should change its icon immediately. + void UpdateReloadStopState(bool is_loading, bool force); + + // Add/remove observers for interstitial attachment/detachment from + // |contents|. + void AddInterstitialObservers(TabContents* contents); + void RemoveInterstitialObservers(TabContents* contents); + + inline BrowserWindow* window(); + inline Profile* profile(); + + Browser* browser_; + + // The CommandUpdater that manages the browser window commands. + CommandUpdater command_updater_; + + // Indicates if command execution is blocked. + bool block_command_execution_; + + // Stores the last blocked command id when |block_command_execution_| is true. + int last_blocked_command_id_; + + // Stores the disposition type of the last blocked command. + WindowOpenDisposition last_blocked_command_disposition_; + + content::NotificationRegistrar registrar_; + PrefChangeRegistrar profile_pref_registrar_; + PrefChangeRegistrar local_pref_registrar_; + + DISALLOW_COPY_AND_ASSIGN(BrowserCommandController); +}; + +} // namespace chrome + +#endif // CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_ |