Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / browser_command_controller.h
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.
4
5 #ifndef CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_
7
8 #include <vector>
9
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"
17
18 class Browser;
19 class BrowserWindow;
20 class Profile;
21
22 namespace content {
23 struct NativeWebKeyboardEvent;
24 }
25
26 namespace chrome {
27
28 class BrowserCommandController : public CommandUpdaterDelegate,
29                                  public TabStripModelObserver,
30                                  public TabRestoreServiceObserver {
31  public:
32   explicit BrowserCommandController(Browser* browser);
33   ~BrowserCommandController() override;
34
35   CommandUpdater* command_updater() { return &command_updater_; }
36   bool block_command_execution() const { return block_command_execution_; }
37
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);
43
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);
49
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);
55
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 ZoomStateChanged();
60   void ContentRestrictionsChanged();
61   void FullscreenStateChanged();
62   void PrintingStateChanged();
63   void LoadingStateChanged(bool is_loading, bool force);
64
65   // Shared state updating: these functions are static and public to share with
66   // outside code.
67
68   // Updates the open-file state.
69   static void UpdateOpenFileState(CommandUpdater* command_updater);
70
71   // Update commands whose state depends on incognito mode availability and that
72   // only depend on the profile.
73   static void UpdateSharedCommandsForIncognitoAvailability(
74       CommandUpdater* command_updater,
75       Profile* profile);
76
77  private:
78   class InterstitialObserver;
79
80   // Overridden from CommandUpdaterDelegate:
81   void ExecuteCommandWithDisposition(int id, WindowOpenDisposition disposition)
82       override;
83
84   // Overridden from TabStripModelObserver:
85   void TabInsertedAt(content::WebContents* contents,
86                      int index,
87                      bool foreground) override;
88   void TabDetachedAt(content::WebContents* contents, int index) override;
89   void TabReplacedAt(TabStripModel* tab_strip_model,
90                      content::WebContents* old_contents,
91                      content::WebContents* new_contents,
92                      int index) override;
93   void TabBlockedStateChanged(content::WebContents* contents,
94                               int index) override;
95
96   // Overridden from TabRestoreServiceObserver:
97   void TabRestoreServiceChanged(TabRestoreService* service) override;
98   void TabRestoreServiceDestroyed(TabRestoreService* service) override;
99   void TabRestoreServiceLoaded(TabRestoreService* service) override;
100
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();
106
107   // Initialize state for all browser commands.
108   void InitCommandState();
109
110   // Update commands whose state depends on incognito mode availability.
111   void UpdateCommandsForIncognitoAvailability();
112
113   // Update commands whose state depends on the tab's state.
114   void UpdateCommandsForTabState();
115
116   // Update Zoom commands based on zoom state.
117   void UpdateCommandsForZoomState();
118
119   // Updates commands when the content's restrictions change.
120   void UpdateCommandsForContentRestrictionState();
121
122   // Updates commands for enabling developer tools.
123   void UpdateCommandsForDevTools();
124
125   // Updates commands for bookmark editing.
126   void UpdateCommandsForBookmarkEditing();
127
128   // Updates commands that affect the bookmark bar.
129   void UpdateCommandsForBookmarkBar();
130
131   // Updates commands that affect file selection dialogs in aggregate,
132   // namely the save-page-as state and the open-file state.
133   void UpdateCommandsForFileSelectionDialogs();
134
135   // Update commands whose state depends on the type of fullscreen mode the
136   // window is in.
137   void UpdateCommandsForFullscreenMode();
138
139   // Updates the printing command state.
140   void UpdatePrintingState();
141
142   // Updates the SHOW_SYNC_SETUP menu entry.
143   void OnSigninAllowedPrefChange();
144
145   // Updates the save-page-as command state.
146   void UpdateSaveAsState();
147
148   // Updates the show-sync command state.
149   void UpdateShowSyncState(bool show_main_ui);
150
151   // Ask the Reload/Stop button to change its icon, and update the Stop command
152   // state.  |is_loading| is true if the current WebContents is loading.
153   // |force| is true if the button should change its icon immediately.
154   void UpdateReloadStopState(bool is_loading, bool force);
155
156   // Updates commands for find.
157   void UpdateCommandsForFind();
158
159   void UpdateTabRestoreCommandState();
160
161   // Add/remove observers for interstitial attachment/detachment from
162   // |contents|.
163   void AddInterstitialObservers(content::WebContents* contents);
164   void RemoveInterstitialObservers(content::WebContents* contents);
165
166   inline BrowserWindow* window();
167   inline Profile* profile();
168
169   Browser* browser_;
170
171   // The CommandUpdater that manages the browser window commands.
172   CommandUpdater command_updater_;
173
174   // Indicates if command execution is blocked.
175   bool block_command_execution_;
176
177   // Stores the last blocked command id when |block_command_execution_| is true.
178   int last_blocked_command_id_;
179
180   // Stores the disposition type of the last blocked command.
181   WindowOpenDisposition last_blocked_command_disposition_;
182
183   std::vector<InterstitialObserver*> interstitial_observers_;
184
185   PrefChangeRegistrar profile_pref_registrar_;
186   PrefChangeRegistrar local_pref_registrar_;
187   BooleanPrefMember pref_signin_allowed_;
188
189   DISALLOW_COPY_AND_ASSIGN(BrowserCommandController);
190 };
191
192 }  // namespace chrome
193
194 #endif  // CHROME_BROWSER_UI_BROWSER_COMMAND_CONTROLLER_H_