Temporarily re-enabling SizeAfterPrefChange test with traces (this time for Linux...
[chromium-blink-merge.git] / chrome / browser / ui / browser_command_controller.h
blobbfba09e1daa495da9aff52ce2a8d7f1f2bcfd499
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 #ifndef CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_
8 #include <vector>
10 #include "base/prefs/pref_change_registrar.h"
11 #include "base/prefs/pref_member.h"
12 #include "chrome/browser/command_updater.h"
13 #include "chrome/browser/command_updater_delegate.h"
14 #include "chrome/browser/sessions/tab_restore_service_observer.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
16 #include "ui/base/window_open_disposition.h"
18 class Browser;
19 class BrowserWindow;
20 class Profile;
22 namespace content {
23 struct NativeWebKeyboardEvent;
26 namespace chrome {
28 class BrowserCommandController : public CommandUpdaterDelegate,
29 public TabStripModelObserver,
30 public TabRestoreServiceObserver {
31 public:
32 explicit BrowserCommandController(Browser* browser);
33 virtual ~BrowserCommandController();
35 CommandUpdater* command_updater() { return &command_updater_; }
36 bool block_command_execution() const { return block_command_execution_; }
38 // Returns true if |command_id| is a reserved command whose keyboard shortcuts
39 // should not be sent to the renderer or |event| was triggered by a key that
40 // we never want to send to the renderer.
41 bool IsReservedCommandOrKey(int command_id,
42 const content::NativeWebKeyboardEvent& event);
44 // Sets if command execution shall be blocked. If |block| is true then
45 // following calls to ExecuteCommand() or ExecuteCommandWithDisposition()
46 // method will not execute the command, and the last blocked command will be
47 // recorded for retrieval.
48 void SetBlockCommandExecution(bool block);
50 // Gets the last blocked command after calling SetBlockCommandExecution(true).
51 // Returns the command id or -1 if there is no command blocked. The
52 // disposition type of the command will be stored in |*disposition| if it's
53 // not NULL.
54 int GetLastBlockedCommand(WindowOpenDisposition* disposition);
56 // Notifies the controller that state has changed in one of the following
57 // areas and it should update command states.
58 void TabStateChanged();
59 void ContentRestrictionsChanged();
60 void FullscreenStateChanged();
61 void PrintingStateChanged();
62 void LoadingStateChanged(bool is_loading, bool force);
64 // Shared state updating: these functions are static and public to share with
65 // outside code.
67 // Updates the open-file state.
68 static void UpdateOpenFileState(CommandUpdater* command_updater);
70 // Update commands whose state depends on incognito mode availability and that
71 // only depend on the profile.
72 static void UpdateSharedCommandsForIncognitoAvailability(
73 CommandUpdater* command_updater,
74 Profile* profile);
76 private:
77 class InterstitialObserver;
79 // Overridden from CommandUpdaterDelegate:
80 virtual void ExecuteCommandWithDisposition(
81 int id,
82 WindowOpenDisposition disposition) OVERRIDE;
84 // Overridden from TabStripModelObserver:
85 virtual void TabInsertedAt(content::WebContents* contents,
86 int index,
87 bool foreground) OVERRIDE;
88 virtual void TabDetachedAt(content::WebContents* contents,
89 int index) OVERRIDE;
90 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
91 content::WebContents* old_contents,
92 content::WebContents* new_contents,
93 int index) OVERRIDE;
94 virtual void TabBlockedStateChanged(content::WebContents* contents,
95 int index) OVERRIDE;
97 // Overridden from TabRestoreServiceObserver:
98 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE;
99 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE;
101 // Returns true if the regular Chrome UI (not the fullscreen one and
102 // not the single-tab one) is shown. Used for updating window command states
103 // only. Consider using SupportsWindowFeature if you need the mentioned
104 // functionality anywhere else.
105 bool IsShowingMainUI();
107 // Initialize state for all browser commands.
108 void InitCommandState();
110 // Update commands whose state depends on incognito mode availability.
111 void UpdateCommandsForIncognitoAvailability();
113 // Update commands whose state depends on the tab's state.
114 void UpdateCommandsForTabState();
116 // Updates commands when the content's restrictions change.
117 void UpdateCommandsForContentRestrictionState();
119 // Updates commands for enabling developer tools.
120 void UpdateCommandsForDevTools();
122 // Updates commands for bookmark editing.
123 void UpdateCommandsForBookmarkEditing();
125 // Updates commands that affect the bookmark bar.
126 void UpdateCommandsForBookmarkBar();
128 // Updates commands that affect file selection dialogs in aggregate,
129 // namely the save-page-as state and the open-file state.
130 void UpdateCommandsForFileSelectionDialogs();
132 // Update commands whose state depends on the type of fullscreen mode the
133 // window is in.
134 void UpdateCommandsForFullscreenMode();
136 // Updates the printing command state.
137 void UpdatePrintingState();
139 // Updates the SHOW_SYNC_SETUP menu entry.
140 void OnSigninAllowedPrefChange();
142 // Updates the save-page-as command state.
143 void UpdateSaveAsState();
145 // Updates the show-sync command state.
146 void UpdateShowSyncState(bool show_main_ui);
148 // Ask the Reload/Stop button to change its icon, and update the Stop command
149 // state. |is_loading| is true if the current WebContents is loading.
150 // |force| is true if the button should change its icon immediately.
151 void UpdateReloadStopState(bool is_loading, bool force);
153 // Updates commands for find.
154 void UpdateCommandsForFind();
156 // Add/remove observers for interstitial attachment/detachment from
157 // |contents|.
158 void AddInterstitialObservers(content::WebContents* contents);
159 void RemoveInterstitialObservers(content::WebContents* contents);
161 inline BrowserWindow* window();
162 inline Profile* profile();
164 Browser* browser_;
166 // The CommandUpdater that manages the browser window commands.
167 CommandUpdater command_updater_;
169 // Indicates if command execution is blocked.
170 bool block_command_execution_;
172 // Stores the last blocked command id when |block_command_execution_| is true.
173 int last_blocked_command_id_;
175 // Stores the disposition type of the last blocked command.
176 WindowOpenDisposition last_blocked_command_disposition_;
178 std::vector<InterstitialObserver*> interstitial_observers_;
180 PrefChangeRegistrar profile_pref_registrar_;
181 PrefChangeRegistrar local_pref_registrar_;
182 BooleanPrefMember pref_signin_allowed_;
184 DISALLOW_COPY_AND_ASSIGN(BrowserCommandController);
187 } // namespace chrome
189 #endif // CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_