Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / browser_command_controller.h
blobda9e995736d43b310fa29ec520c3ff71051d0ebc
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/profiles/profile_info_cache_observer.h"
15 #include "chrome/browser/sessions/tab_restore_service_observer.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
17 #include "ui/base/window_open_disposition.h"
19 class Browser;
20 class BrowserWindow;
21 class Profile;
22 class ProfileManager;
24 namespace content {
25 struct NativeWebKeyboardEvent;
28 namespace chrome {
30 class BrowserCommandController : public CommandUpdaterDelegate,
31 public ProfileInfoCacheObserver,
32 public TabStripModelObserver,
33 public TabRestoreServiceObserver {
34 public:
35 BrowserCommandController(Browser* browser, ProfileManager* profile_manager);
36 virtual ~BrowserCommandController();
38 CommandUpdater* command_updater() { return &command_updater_; }
39 bool block_command_execution() const { return block_command_execution_; }
41 // Returns true if |command_id| is a reserved command whose keyboard shortcuts
42 // should not be sent to the renderer or |event| was triggered by a key that
43 // we never want to send to the renderer.
44 bool IsReservedCommandOrKey(int command_id,
45 const content::NativeWebKeyboardEvent& event);
47 // Sets if command execution shall be blocked. If |block| is true then
48 // following calls to ExecuteCommand() or ExecuteCommandWithDisposition()
49 // method will not execute the command, and the last blocked command will be
50 // recorded for retrieval.
51 void SetBlockCommandExecution(bool block);
53 // Gets the last blocked command after calling SetBlockCommandExecution(true).
54 // Returns the command id or -1 if there is no command blocked. The
55 // disposition type of the command will be stored in |*disposition| if it's
56 // not NULL.
57 int GetLastBlockedCommand(WindowOpenDisposition* disposition);
59 // Notifies the controller that state has changed in one of the following
60 // areas and it should update command states.
61 void TabStateChanged();
62 void ContentRestrictionsChanged();
63 void FullscreenStateChanged();
64 void PrintingStateChanged();
65 void LoadingStateChanged(bool is_loading, bool force);
67 // Shared state updating: these functions are static and public to share with
68 // outside code.
70 // Updates the open-file state.
71 static void UpdateOpenFileState(CommandUpdater* command_updater);
73 // Update commands whose state depends on incognito mode availability and that
74 // only depend on the profile.
75 static void UpdateSharedCommandsForIncognitoAvailability(
76 CommandUpdater* command_updater,
77 Profile* profile);
79 private:
80 class InterstitialObserver;
82 // Overridden from CommandUpdaterDelegate:
83 virtual void ExecuteCommandWithDisposition(
84 int id,
85 WindowOpenDisposition disposition) OVERRIDE;
87 // Overridden from ProfileInfoCacheObserver:
88 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE;
89 virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
90 const base::string16& profile_name) OVERRIDE;
92 // Overridden from TabStripModelObserver:
93 virtual void TabInsertedAt(content::WebContents* contents,
94 int index,
95 bool foreground) OVERRIDE;
96 virtual void TabDetachedAt(content::WebContents* contents,
97 int index) OVERRIDE;
98 virtual void TabReplacedAt(TabStripModel* tab_strip_model,
99 content::WebContents* old_contents,
100 content::WebContents* new_contents,
101 int index) OVERRIDE;
102 virtual void TabBlockedStateChanged(content::WebContents* contents,
103 int index) OVERRIDE;
105 // Overridden from TabRestoreServiceObserver:
106 virtual void TabRestoreServiceChanged(TabRestoreService* service) OVERRIDE;
107 virtual void TabRestoreServiceDestroyed(TabRestoreService* service) OVERRIDE;
109 // Returns true if the regular Chrome UI (not the fullscreen one and
110 // not the single-tab one) is shown. Used for updating window command states
111 // only. Consider using SupportsWindowFeature if you need the mentioned
112 // functionality anywhere else.
113 bool IsShowingMainUI();
115 // Initialize state for all browser commands.
116 void InitCommandState();
118 // Update commands whose state depends on incognito mode availability.
119 void UpdateCommandsForIncognitoAvailability();
121 // Update commands whose state depends on the tab's state.
122 void UpdateCommandsForTabState();
124 // Updates commands when the content's restrictions change.
125 void UpdateCommandsForContentRestrictionState();
127 // Updates commands for enabling developer tools.
128 void UpdateCommandsForDevTools();
130 // Updates commands for bookmark editing.
131 void UpdateCommandsForBookmarkEditing();
133 // Updates commands that affect the bookmark bar.
134 void UpdateCommandsForBookmarkBar();
136 // Updates commands that affect file selection dialogs in aggregate,
137 // namely the save-page-as state and the open-file state.
138 void UpdateCommandsForFileSelectionDialogs();
140 // Update commands whose state depends on the type of fullscreen mode the
141 // window is in.
142 void UpdateCommandsForFullscreenMode();
144 // Update commands whose state depends on whether multiple profiles are
145 // allowed.
146 void UpdateCommandsForMultipleProfiles();
148 // Updates the printing command state.
149 void UpdatePrintingState();
151 // Updates the SHOW_SYNC_SETUP menu entry.
152 void OnSigninAllowedPrefChange();
154 // Updates the save-page-as command state.
155 void UpdateSaveAsState();
157 // Updates the show-sync command state.
158 void UpdateShowSyncState(bool show_main_ui);
160 // Ask the Reload/Stop button to change its icon, and update the Stop command
161 // state. |is_loading| is true if the current WebContents is loading.
162 // |force| is true if the button should change its icon immediately.
163 void UpdateReloadStopState(bool is_loading, bool force);
165 // Updates commands for find.
166 void UpdateCommandsForFind();
168 // Add/remove observers for interstitial attachment/detachment from
169 // |contents|.
170 void AddInterstitialObservers(content::WebContents* contents);
171 void RemoveInterstitialObservers(content::WebContents* contents);
173 inline BrowserWindow* window();
174 inline Profile* profile();
176 Browser* browser_;
178 ProfileManager* profile_manager_;
180 // The CommandUpdater that manages the browser window commands.
181 CommandUpdater command_updater_;
183 // Indicates if command execution is blocked.
184 bool block_command_execution_;
186 // Stores the last blocked command id when |block_command_execution_| is true.
187 int last_blocked_command_id_;
189 // Stores the disposition type of the last blocked command.
190 WindowOpenDisposition last_blocked_command_disposition_;
192 std::vector<InterstitialObserver*> interstitial_observers_;
194 PrefChangeRegistrar profile_pref_registrar_;
195 PrefChangeRegistrar local_pref_registrar_;
196 BooleanPrefMember pref_signin_allowed_;
198 DISALLOW_COPY_AND_ASSIGN(BrowserCommandController);
201 } // namespace chrome
203 #endif // CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_