OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | |
9 #include <map> | |
10 #include <set> | |
8 #include <string> | 11 #include <string> |
12 #include <vector> | |
9 | 13 |
14 #include "ash/display/display_controller.h" | |
10 #include "ash/launcher/launcher_delegate.h" | 15 #include "ash/launcher/launcher_delegate.h" |
16 #include "ash/launcher/launcher_model_observer.h" | |
11 #include "ash/launcher/launcher_types.h" | 17 #include "ash/launcher/launcher_types.h" |
18 #include "ash/shelf/shelf_layout_manager_observer.h" | |
12 #include "ash/shelf/shelf_types.h" | 19 #include "ash/shelf/shelf_types.h" |
20 #include "ash/shell_observer.h" | |
21 #include "base/basictypes.h" | |
22 #include "base/compiler_specific.h" | |
23 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/scoped_vector.h" | 24 #include "base/memory/scoped_vector.h" |
25 #include "base/prefs/pref_change_registrar.h" | |
14 #include "chrome/browser/extensions/app_icon_loader.h" | 26 #include "chrome/browser/extensions/app_icon_loader.h" |
15 #include "chrome/browser/extensions/extension_prefs.h" | 27 #include "chrome/browser/extensions/extension_prefs.h" |
28 #include "chrome/browser/prefs/pref_service_syncable_observer.h" | |
29 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" | |
30 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | |
31 #include "chrome/browser/ui/browser_list_observer.h" | |
32 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" | |
33 #include "content/public/browser/notification_observer.h" | |
34 #include "ui/aura/window_observer.h" | |
16 | 35 |
17 class LauncherItemControllerPerAppTest; | 36 class AppSyncUIState; |
37 class Browser; | |
38 class BrowserShortcutLauncherItemController; | |
39 class ExtensionEnableFlow; | |
40 class GURL; | |
18 class LauncherItemController; | 41 class LauncherItemController; |
19 class Profile; | 42 class Profile; |
20 class ChromeLauncherAppMenuItem; | 43 class ShellWindowLauncherController; |
21 class ChromeLauncherControllerPerApp; | 44 class TabContents; |
22 | 45 |
23 namespace ash { | 46 namespace ash { |
24 class LauncherModel; | 47 class LauncherModel; |
25 } | 48 } |
26 | 49 |
27 namespace aura { | 50 namespace aura { |
28 class Window; | 51 class Window; |
29 class RootWindow; | |
30 } | 52 } |
31 | 53 |
32 namespace content { | 54 namespace content { |
55 class NotificationRegistrar; | |
33 class WebContents; | 56 class WebContents; |
34 } | 57 } |
35 | 58 |
36 namespace ui { | 59 namespace ui { |
37 class BaseWindow; | 60 class BaseWindow; |
38 } | 61 } |
39 | 62 |
40 // A list of the elements which makes up a simple menu description. | 63 // A list of the elements which makes up a simple menu description. |
41 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; | 64 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; |
42 | 65 |
43 // ChromeLauncherController manages the launcher items needed for content | 66 // ChromeLauncherController manages the launcher items needed for content |
44 // windows. Launcher items have a type, an optional app id, and a controller. | 67 // content windows. Launcher items have a type, an optional app id, and a |
James Cook
2013/08/19 22:32:38
nit: "content content" - remove one word :-)
simonhong_
2013/08/20 01:11:20
Done.
| |
45 // ChromeLauncherController will furthermore create the particular | 68 // controller. This incarnation groups running tabs/windows in application |
46 // implementation of interest - either sorting by application (new) or sorting | 69 // specific lists. |
47 // by browser (old). | 70 // * Browser app windows have BrowserLauncherItemController, owned by the |
48 // * Tabbed browsers and browser app windows have BrowserLauncherItemController, | 71 // BrowserView instance. |
49 // owned by the BrowserView instance. | |
50 // * App shell windows have ShellWindowLauncherItemController, owned by | 72 // * App shell windows have ShellWindowLauncherItemController, owned by |
51 // ShellWindowLauncherController. | 73 // ShellWindowLauncherController. |
52 // * Shortcuts have no LauncherItemController. | 74 // * Shortcuts have no LauncherItemController. |
53 class ChromeLauncherController | 75 class ChromeLauncherController : public ash::LauncherDelegate, |
54 : public ash::LauncherDelegate, | 76 public ash::LauncherModelObserver, |
55 public extensions::AppIconLoader::Delegate { | 77 public ash::ShellObserver, |
78 public ash::DisplayController::Observer, | |
79 public content::NotificationObserver, | |
80 public extensions::AppIconLoader::Delegate, | |
81 public PrefServiceSyncableObserver, | |
82 public AppSyncUIStateObserver, | |
83 public ExtensionEnableFlowDelegate, | |
84 public chrome::BrowserListObserver, | |
85 public ash::ShelfLayoutManagerObserver { | |
56 public: | 86 public: |
57 // Indicates if a launcher item is incognito or not. | 87 // Indicates if a launcher item is incognito or not. |
58 enum IncognitoState { | 88 enum IncognitoState { |
59 STATE_INCOGNITO, | 89 STATE_INCOGNITO, |
60 STATE_NOT_INCOGNITO, | 90 STATE_NOT_INCOGNITO, |
61 }; | 91 }; |
62 | 92 |
63 // Used to update the state of non plaform apps, as web contents change. | 93 // Used to update the state of non plaform apps, as web contents change. |
64 enum AppState { | 94 enum AppState { |
65 APP_STATE_ACTIVE, | 95 APP_STATE_ACTIVE, |
66 APP_STATE_WINDOW_ACTIVE, | 96 APP_STATE_WINDOW_ACTIVE, |
67 APP_STATE_INACTIVE, | 97 APP_STATE_INACTIVE, |
68 APP_STATE_REMOVED | 98 APP_STATE_REMOVED |
69 }; | 99 }; |
70 | 100 |
71 // Mockable interface to get app ids from tabs. | 101 // Mockable interface to get app ids from tabs. |
72 class AppTabHelper { | 102 class AppTabHelper { |
73 public: | 103 public: |
74 virtual ~AppTabHelper() {} | 104 virtual ~AppTabHelper() {} |
75 | 105 |
76 // Returns the app id of the specified tab, or an empty string if there is | 106 // Returns the app id of the specified tab, or an empty string if there is |
77 // no app. | 107 // no app. |
78 virtual std::string GetAppID(content::WebContents* tab) = 0; | 108 virtual std::string GetAppID(content::WebContents* tab) = 0; |
79 | 109 |
80 // Returns true if |id| is valid. Used during restore to ignore no longer | 110 // Returns true if |id| is valid. Used during restore to ignore no longer |
81 // valid extensions. | 111 // valid extensions. |
82 virtual bool IsValidID(const std::string& id) = 0; | 112 virtual bool IsValidID(const std::string& id) = 0; |
83 }; | 113 }; |
84 | 114 |
85 ChromeLauncherController() {} | 115 ChromeLauncherController(Profile* profile, ash::LauncherModel* model); |
86 virtual ~ChromeLauncherController(); | 116 virtual ~ChromeLauncherController(); |
87 | 117 |
88 // Initializes this ChromeLauncherController. | 118 // Initializes this ChromeLauncherController. |
89 virtual void Init() = 0; | 119 virtual void Init() OVERRIDE; |
James Cook
2013/08/19 22:32:38
Do you need virtual? OVERRIDE? I suspect you do
simonhong_
2013/08/20 01:11:20
Yes, there are so many unwanted virtual & OVERRIDE
| |
90 | |
91 // Returns the new per application interface of the given launcher. If it is | |
92 // a per browser (old) controller, it will return NULL; | |
93 // TODO(skuhne): Remove when we rip out the old launcher. | |
94 virtual ChromeLauncherControllerPerApp* GetPerAppInterface() = 0; | |
95 | 120 |
96 // Creates an instance. | 121 // Creates an instance. |
97 static ChromeLauncherController* CreateInstance(Profile* profile, | 122 static ChromeLauncherController* CreateInstance(Profile* profile, |
98 ash::LauncherModel* model); | 123 ash::LauncherModel* model); |
99 | 124 |
100 // Returns the single ChromeLauncherController instance. | 125 // Returns the single ChromeLauncherController instance. |
101 static ChromeLauncherController* instance() { return instance_; } | 126 static ChromeLauncherController* instance() { return instance_; } |
102 | 127 |
103 // Creates a new tabbed item on the launcher for |controller|. | |
104 virtual ash::LauncherID CreateTabbedLauncherItem( | |
105 LauncherItemController* controller, | |
106 IncognitoState is_incognito, | |
107 ash::LauncherItemStatus status) = 0; | |
108 | |
109 // Creates a new app item on the launcher for |controller|. | 128 // Creates a new app item on the launcher for |controller|. |
110 virtual ash::LauncherID CreateAppLauncherItem( | 129 virtual ash::LauncherID CreateAppLauncherItem( |
111 LauncherItemController* controller, | 130 LauncherItemController* controller, |
112 const std::string& app_id, | 131 const std::string& app_id, |
113 ash::LauncherItemStatus status) = 0; | 132 ash::LauncherItemStatus status) OVERRIDE; |
114 | 133 |
115 // Updates the running status of an item. | 134 // Updates the running status of an item. It will also update the status of |
135 // browsers launcher item if needed. | |
116 virtual void SetItemStatus(ash::LauncherID id, | 136 virtual void SetItemStatus(ash::LauncherID id, |
117 ash::LauncherItemStatus status) = 0; | 137 ash::LauncherItemStatus status) OVERRIDE; |
118 | 138 |
119 // Updates the controller associated with id (which should be a shortcut). | 139 // Updates the controller associated with id (which should be a shortcut). |
120 // |controller| remains owned by caller. | 140 // |controller| remains owned by caller. |
121 virtual void SetItemController(ash::LauncherID id, | 141 virtual void SetItemController(ash::LauncherID id, |
122 LauncherItemController* controller) = 0; | 142 LauncherItemController* controller) OVERRIDE; |
123 | 143 |
124 // Closes or unpins the launcher item. | 144 // Closes or unpins the launcher item. |
125 virtual void CloseLauncherItem(ash::LauncherID id) = 0; | 145 virtual void CloseLauncherItem(ash::LauncherID id) OVERRIDE; |
126 | 146 |
127 // Pins the specified id. Currently only supports platform apps. | 147 // Pins the specified id. Currently only supports platform apps. |
128 virtual void Pin(ash::LauncherID id) = 0; | 148 virtual void Pin(ash::LauncherID id) OVERRIDE; |
129 | 149 |
130 // Unpins the specified id, closing if not running. | 150 // Unpins the specified id, closing if not running. |
131 virtual void Unpin(ash::LauncherID id) = 0; | 151 virtual void Unpin(ash::LauncherID id) OVERRIDE; |
132 | 152 |
133 // Returns true if the item identified by |id| is pinned. | 153 // Returns true if the item identified by |id| is pinned. |
134 virtual bool IsPinned(ash::LauncherID id) = 0; | 154 virtual bool IsPinned(ash::LauncherID id) OVERRIDE; |
135 | 155 |
136 // Pins/unpins the specified id. | 156 // Pins/unpins the specified id. |
137 virtual void TogglePinned(ash::LauncherID id) = 0; | 157 virtual void TogglePinned(ash::LauncherID id) OVERRIDE; |
138 | 158 |
139 // Returns true if the specified item can be pinned or unpinned. Only apps can | 159 // Returns true if the specified item can be pinned or unpinned. Only apps can |
140 // be pinned. | 160 // be pinned. |
141 virtual bool IsPinnable(ash::LauncherID id) const = 0; | 161 virtual bool IsPinnable(ash::LauncherID id) const OVERRIDE; |
142 | 162 |
143 // If there is no launcher item in the launcher for application |app_id|, one | 163 // If there is no launcher item in the launcher for application |app_id|, one |
144 // gets created. The (existing or created) launcher items get then locked | 164 // gets created. The (existing or created) launcher items get then locked |
145 // against a users un-pinning removal. | 165 // against a users un-pinning removal. |
146 virtual void LockV1AppWithID(const std::string& app_id) = 0; | 166 virtual void LockV1AppWithID(const std::string& app_id) OVERRIDE; |
147 | 167 |
148 // A previously locked launcher item of type |app_id| gets unlocked. If the | 168 // A previously locked launcher item of type |app_id| gets unlocked. If the |
149 // lock count reaches 0 and the item is not pinned it will go away. | 169 // lock count reaches 0 and the item is not pinned it will go away. |
150 virtual void UnlockV1AppWithID(const std::string& app_id) = 0; | 170 virtual void UnlockV1AppWithID(const std::string& app_id) OVERRIDE; |
151 | 171 |
152 // Requests that the launcher item controller specified by |id| open a new | 172 // Requests that the launcher item controller specified by |id| open a new |
153 // instance of the app. |event_flags| holds the flags of the event which | 173 // instance of the app. |event_flags| holds the flags of the event which |
154 // triggered this command. | 174 // triggered this command. |
155 virtual void Launch(ash::LauncherID id, int event_flags) = 0; | 175 virtual void Launch(ash::LauncherID id, int event_flags) OVERRIDE; |
156 | 176 |
157 // Closes the specified item. | 177 // Closes the specified item. |
158 virtual void Close(ash::LauncherID id) = 0; | 178 virtual void Close(ash::LauncherID id) OVERRIDE; |
159 | 179 |
160 // Returns true if the specified item is open. | 180 // Returns true if the specified item is open. |
161 virtual bool IsOpen(ash::LauncherID id) = 0; | 181 virtual bool IsOpen(ash::LauncherID id) OVERRIDE; |
162 | 182 |
163 // Returns true if the specified item is for a platform app. | 183 // Returns true if the specified item is for a platform app. |
164 virtual bool IsPlatformApp(ash::LauncherID id) = 0; | 184 virtual bool IsPlatformApp(ash::LauncherID id) OVERRIDE; |
165 | 185 |
166 // Opens a new instance of the application identified by |app_id|. | 186 // Opens a new instance of the application identified by |app_id|. |
167 // Used by the app-list, and by pinned-app launcher items. | 187 // Used by the app-list, and by pinned-app launcher items. |
168 virtual void LaunchApp(const std::string& app_id, int event_flags) = 0; | 188 virtual void LaunchApp(const std::string& app_id, int event_flags) OVERRIDE; |
169 | 189 |
170 // If |app_id| is running, reactivates the app's most recently active window, | 190 // If |app_id| is running, reactivates the app's most recently active window, |
171 // otherwise launches and activates the app. | 191 // otherwise launches and activates the app. |
172 // Used by the app-list, and by pinned-app launcher items. | 192 // Used by the app-list, and by pinned-app launcher items. |
173 virtual void ActivateApp(const std::string& app_id, int event_flags) = 0; | 193 virtual void ActivateApp(const std::string& app_id, int event_flags) OVERRIDE; |
174 | 194 |
175 // Returns the launch type of app for the specified id. | 195 // Returns the launch type of app for the specified id. |
176 virtual extensions::ExtensionPrefs::LaunchType GetLaunchType( | 196 virtual extensions::ExtensionPrefs::LaunchType GetLaunchType( |
177 ash::LauncherID id) = 0; | 197 ash::LauncherID id) OVERRIDE; |
178 | 198 |
179 // Returns the id of the app for the specified tab. | 199 // Returns the id of the app for the specified tab. |
180 virtual std::string GetAppID(content::WebContents* tab) = 0; | 200 virtual std::string GetAppID(content::WebContents* tab) OVERRIDE; |
181 | 201 |
182 // Returns the launcherID of the first non-panel item whose app_id | 202 // Returns the |LauncherModel|'s ID or 0 if the AppId was not found. |
183 // matches |app_id| or 0 if none match. | 203 virtual ash::LauncherID GetLauncherIDForAppID( |
184 virtual ash::LauncherID GetLauncherIDForAppID(const std::string& app_id) = 0; | 204 const std::string& app_id) OVERRIDE; |
185 | 205 virtual std::string GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE; |
186 // Returns the id of the app for the specified id (which must exist). | |
187 virtual std::string GetAppIDForLauncherID(ash::LauncherID id) = 0; | |
188 | 206 |
189 // Set the image for a specific launcher item (e.g. when set by the app). | 207 // Set the image for a specific launcher item (e.g. when set by the app). |
190 virtual void SetLauncherItemImage(ash::LauncherID launcher_id, | 208 virtual void SetLauncherItemImage(ash::LauncherID launcher_id, |
191 const gfx::ImageSkia& image) = 0; | 209 const gfx::ImageSkia& image) OVERRIDE; |
192 | 210 |
193 // Returns true if a pinned launcher item with given |app_id| could be found. | 211 // Returns true if a pinned launcher item with given |app_id| could be found. |
194 virtual bool IsAppPinned(const std::string& app_id) = 0; | 212 virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; |
213 | |
214 // Find out if the given application |id| is a windowed app item and not a | |
215 // pinned item in the launcher. | |
216 bool IsWindowedAppInLauncher(const std::string& app_id); | |
195 | 217 |
196 // Pins an app with |app_id| to launcher. If there is a running instance in | 218 // Pins an app with |app_id| to launcher. If there is a running instance in |
197 // launcher, the running instance is pinned. If there is no running instance, | 219 // launcher, the running instance is pinned. If there is no running instance, |
198 // a new launcher item is created and pinned. | 220 // a new launcher item is created and pinned. |
199 virtual void PinAppWithID(const std::string& app_id) = 0; | 221 virtual void PinAppWithID(const std::string& app_id) OVERRIDE; |
200 | 222 |
201 // Updates the launche type of the app for the specified id to |launch_type|. | 223 // Updates the launche type of the app for the specified id to |launch_type|. |
202 virtual void SetLaunchType( | 224 virtual void SetLaunchType( |
203 ash::LauncherID id, | 225 ash::LauncherID id, |
204 extensions::ExtensionPrefs::LaunchType launch_type) = 0; | 226 extensions::ExtensionPrefs::LaunchType launch_type) OVERRIDE; |
205 | 227 |
206 // Unpins any app items whose id is |app_id|. | 228 // Unpins any app items whose id is |app_id|. |
207 virtual void UnpinAppsWithID(const std::string& app_id) = 0; | 229 virtual void UnpinAppsWithID(const std::string& app_id) OVERRIDE; |
208 | 230 |
209 // Returns true if the user is currently logged in as a guest. | 231 // Returns true if the user is currently logged in as a guest. |
210 virtual bool IsLoggedInAsGuest() = 0; | 232 virtual bool IsLoggedInAsGuest() OVERRIDE; |
211 | 233 |
212 // Invoked when user clicks on button in the launcher and there is no last | 234 // Invoked when user clicks on button in the launcher and there is no last |
213 // used window (or CTRL is held with the click). | 235 // used window (or CTRL is held with the click). |
214 virtual void CreateNewWindow() = 0; | 236 virtual void CreateNewWindow() OVERRIDE; |
215 | 237 |
216 // Invoked when the user clicks on button in the launcher to create a new | 238 // Invoked when the user clicks on button in the launcher to create a new |
217 // incognito window. | 239 // incognito window. |
218 virtual void CreateNewIncognitoWindow() = 0; | 240 virtual void CreateNewIncognitoWindow() OVERRIDE; |
219 | 241 |
220 // Checks whether the user is allowed to pin apps. Pinning may be disallowed | 242 // Checks whether the user is allowed to pin apps. Pinning may be disallowed |
221 // by policy in case there is a pre-defined set of pinned apps. | 243 // by policy in case there is a pre-defined set of pinned apps. |
222 virtual bool CanPin() const = 0; | 244 virtual bool CanPin() const OVERRIDE; |
223 | 245 |
224 // Updates the pinned pref state. The pinned state consists of a list pref. | 246 // Updates the pinned pref state. The pinned state consists of a list pref. |
225 // Each item of the list is a dictionary. The key |kAppIDPath| gives the | 247 // Each item of the list is a dictionary. The key |kAppIDPath| gives the |
226 // id of the app. | 248 // id of the app. |
227 virtual void PersistPinnedState() = 0; | 249 virtual void PersistPinnedState() OVERRIDE; |
228 | 250 |
229 virtual ash::LauncherModel* model() = 0; | 251 virtual ash::LauncherModel* model() OVERRIDE; |
230 | 252 |
231 virtual Profile* profile() = 0; | 253 virtual Profile* profile() OVERRIDE; |
232 | 254 |
233 // Gets the shelf auto-hide behavior on |root_window|. | 255 // Gets the shelf auto-hide behavior on |root_window|. |
234 virtual ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( | 256 virtual ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( |
235 aura::RootWindow* root_window) const = 0; | 257 aura::RootWindow* root_window) const OVERRIDE; |
236 | 258 |
237 // Returns |true| if the user is allowed to modify the shelf auto-hide | 259 // Returns |true| if the user is allowed to modify the shelf auto-hide |
238 // behavior on |root_window|. | 260 // behavior on |root_window|. |
239 virtual bool CanUserModifyShelfAutoHideBehavior( | 261 virtual bool CanUserModifyShelfAutoHideBehavior( |
240 aura::RootWindow* root_window) const = 0; | 262 aura::RootWindow* root_window) const OVERRIDE; |
241 | 263 |
242 // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the | 264 // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the |
243 // user is not allowed to modify the auto-hide behavior. | 265 // user is not allowed to modify the auto-hide behavior. |
244 virtual void ToggleShelfAutoHideBehavior(aura::RootWindow* root_window) = 0; | 266 virtual void ToggleShelfAutoHideBehavior( |
267 aura::RootWindow* root_window) OVERRIDE; | |
245 | 268 |
246 // The tab no longer represents its previously identified application. | 269 // The tab no longer represents its previously identified application. |
247 virtual void RemoveTabFromRunningApp(content::WebContents* tab, | 270 virtual void RemoveTabFromRunningApp(content::WebContents* tab, |
248 const std::string& app_id) = 0; | 271 const std::string& app_id) OVERRIDE; |
249 | 272 |
250 // Notify the controller that the state of an non platform app's tabs | 273 // Notify the controller that the state of an non platform app's tabs |
251 // have changed, | 274 // have changed, |
252 virtual void UpdateAppState(content::WebContents* contents, | 275 virtual void UpdateAppState(content::WebContents* contents, |
253 AppState app_state) = 0; | 276 AppState app_state) OVERRIDE; |
254 | 277 |
255 // Limits application refocusing to urls that match |url| for |id|. | 278 // Limits application refocusing to urls that match |url| for |id|. |
256 virtual void SetRefocusURLPatternForTest(ash::LauncherID id, | 279 virtual void SetRefocusURLPatternForTest(ash::LauncherID id, |
257 const GURL& url) = 0; | 280 const GURL& url) OVERRIDE; |
258 | 281 |
259 // Returns the extension identified by |app_id|. | 282 // Returns the extension identified by |app_id|. |
260 virtual const extensions::Extension* GetExtensionForAppID( | 283 virtual const extensions::Extension* GetExtensionForAppID( |
261 const std::string& app_id) const = 0; | 284 const std::string& app_id) const OVERRIDE; |
262 | 285 |
263 // Activates a |window|. If |allow_minimize| is true and the system allows | 286 // Activates a |window|. If |allow_minimize| is true and the system allows |
264 // it, the the window will get minimized instead. | 287 // it, the the window will get minimized instead. |
265 virtual void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, | 288 virtual void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, |
266 bool allow_minimize) = 0; | 289 bool allow_minimize) OVERRIDE; |
290 | |
267 // ash::LauncherDelegate overrides: | 291 // ash::LauncherDelegate overrides: |
268 virtual void ItemSelected(const ash::LauncherItem& item, | 292 virtual void ItemSelected(const ash::LauncherItem& item, |
269 const ui::Event& event) OVERRIDE = 0; | 293 const ui::Event& event) OVERRIDE; |
270 virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE = 0; | 294 virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE; |
271 virtual ui::MenuModel* CreateContextMenu( | 295 virtual ui::MenuModel* CreateContextMenu( |
272 const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE = 0; | 296 const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE; |
273 virtual ash::LauncherMenuModel* CreateApplicationMenu( | 297 virtual ash::LauncherMenuModel* CreateApplicationMenu( |
274 const ash::LauncherItem& item, | 298 const ash::LauncherItem& item, |
275 int event_flags) OVERRIDE = 0; | 299 int event_flags) OVERRIDE; |
276 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE = 0; | 300 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; |
277 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE = 0; | 301 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; |
278 virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE = 0; | 302 virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE; |
279 virtual bool IsPerAppLauncher() OVERRIDE; | 303 virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; |
304 virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE; | |
305 | |
306 // ash::LauncherModelObserver overrides: | |
307 virtual void LauncherItemAdded(int index) OVERRIDE; | |
308 virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; | |
309 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; | |
310 virtual void LauncherItemChanged(int index, | |
311 const ash::LauncherItem& old_item) OVERRIDE; | |
312 virtual void LauncherStatusChanged() OVERRIDE; | |
313 | |
314 // content::NotificationObserver overrides: | |
315 virtual void Observe(int type, | |
316 const content::NotificationSource& source, | |
317 const content::NotificationDetails& details) OVERRIDE; | |
318 | |
319 // ash::ShellObserver overrides: | |
320 virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE; | |
321 | |
322 // ash::DisplayController::Observer overrides: | |
323 virtual void OnDisplayConfigurationChanging() OVERRIDE; | |
324 virtual void OnDisplayConfigurationChanged() OVERRIDE; | |
325 | |
326 // PrefServiceSyncableObserver overrides: | |
327 virtual void OnIsSyncingChanged() OVERRIDE; | |
328 | |
329 // AppSyncUIStateObserver overrides: | |
330 virtual void OnAppSyncUIStatusChanged() OVERRIDE; | |
331 | |
332 // ExtensionEnableFlowDelegate overrides: | |
333 virtual void ExtensionEnableFlowFinished() OVERRIDE; | |
334 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; | |
280 | 335 |
281 // extensions::AppIconLoader overrides: | 336 // extensions::AppIconLoader overrides: |
282 virtual void SetAppImage(const std::string& app_id, | 337 virtual void SetAppImage(const std::string& app_id, |
283 const gfx::ImageSkia& image) OVERRIDE = 0; | 338 const gfx::ImageSkia& image) OVERRIDE; |
339 | |
340 // ash::ShelfLayoutManagerObserver overrides: | |
341 virtual void OnAutoHideBehaviorChanged( | |
342 aura::RootWindow* root_window, | |
343 ash::ShelfAutoHideBehavior new_behavior) OVERRIDE; | |
344 | |
345 // Get the list of all running incarnations of this item. | |
346 // |event_flags| specifies the flags which were set by the event which | |
347 // triggered this menu generation. It can be used to generate different lists. | |
348 ChromeLauncherAppMenuItems GetApplicationList(const ash::LauncherItem& item, | |
349 int event_flags); | |
350 | |
351 // Get the list of all tabs which belong to a certain application type. | |
352 std::vector<content::WebContents*> GetV1ApplicationsFromAppId( | |
353 std::string app_id); | |
354 | |
355 // Activates a specified shell application. | |
356 void ActivateShellApp(const std::string& app_id, int index); | |
357 | |
358 // Checks if a given |web_contents| is known to be associated with an | |
359 // application of type |app_id|. | |
360 bool IsWebContentHandledByApplication(content::WebContents* web_contents, | |
361 const std::string& app_id); | |
362 | |
363 // Check if the gMail app is loaded and it can handle the given web content. | |
364 // This special treatment is required to address crbug.com/234268. | |
365 bool ContentCanBeHandledByGmailApp(content::WebContents* web_contents); | |
366 | |
367 // Get the favicon for the application list entry for |web_contents|. | |
368 // Note that for incognito windows the incognito icon will be returned. | |
369 // If |web_contents| has not loaded, returns the default favicon. | |
370 gfx::Image GetAppListIcon(content::WebContents* web_contents) const; | |
371 | |
372 // Get the title for the applicatoin list entry for |web_contents|. | |
373 // If |web_contents| has not loaded, returns "Net Tab". | |
374 string16 GetAppListTitle(content::WebContents* web_contents) const; | |
375 | |
376 // Overridden from chrome::BrowserListObserver. | |
377 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | |
378 | |
379 // Returns true when the given |browser| is listed in the browser application | |
380 // list. | |
381 bool IsBrowserRepresentedInBrowserList(Browser* browser); | |
382 | |
383 // Returns the LauncherItemController of BrowserShortcut. | |
384 LauncherItemController* GetBrowserShortcutLauncherItemController(); | |
284 | 385 |
285 protected: | 386 protected: |
286 friend class LauncherItemControllerPerAppTest; | |
287 friend class LauncherPlatformAppBrowserTest; | |
288 friend class LauncherAppBrowserTest; | |
289 // TODO(skuhne): Remove these when the old launcher get removed. | |
290 friend class LauncherPlatformPerAppAppBrowserTest; | |
291 friend class LauncherPerAppAppBrowserTest; | |
292 | |
293 // Creates a new app shortcut item and controller on the launcher at |index|. | 387 // Creates a new app shortcut item and controller on the launcher at |index|. |
294 // Use kInsertItemAtEnd to add a shortcut as the last item. | 388 // Use kInsertItemAtEnd to add a shortcut as the last item. |
295 virtual ash::LauncherID CreateAppShortcutLauncherItem( | 389 virtual ash::LauncherID CreateAppShortcutLauncherItem( |
296 const std::string& app_id, | 390 const std::string& app_id, |
297 int index) = 0; | 391 int index) OVERRIDE; |
298 | 392 |
299 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. | 393 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. |
300 // These are intended for testing. | 394 // These are intended for testing. |
301 virtual void SetAppTabHelperForTest(AppTabHelper* helper) = 0; | 395 virtual void SetAppTabHelperForTest(AppTabHelper* helper) OVERRIDE; |
302 virtual void SetAppIconLoaderForTest(extensions::AppIconLoader* loader) = 0; | 396 virtual void SetAppIconLoaderForTest( |
397 extensions::AppIconLoader* loader) OVERRIDE; | |
303 virtual const std::string& GetAppIdFromLauncherIdForTest( | 398 virtual const std::string& GetAppIdFromLauncherIdForTest( |
304 ash::LauncherID id) = 0; | 399 ash::LauncherID id) OVERRIDE; |
305 | 400 |
306 private: | 401 private: |
402 friend class ChromeLauncherControllerTest; | |
403 friend class LauncherAppBrowserTest; | |
404 friend class LauncherPlatformAppBrowserTest; | |
405 | |
406 typedef std::map<ash::LauncherID, LauncherItemController*> | |
407 IDToItemControllerMap; | |
408 typedef std::list<content::WebContents*> WebContentsList; | |
409 typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; | |
410 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; | |
411 | |
412 // Creates a new app shortcut item and controller on the launcher at |index|. | |
413 // Use kInsertItemAtEnd to add a shortcut as the last item. | |
414 virtual ash::LauncherID CreateAppShortcutLauncherItemWithType( | |
415 const std::string& app_id, | |
416 int index, | |
417 ash::LauncherItemType launcher_item_type); | |
418 | |
419 // Updates the activation state of the Broswer item. | |
420 void UpdateBrowserItemStatus(); | |
421 | |
422 // Returns the profile used for new windows. | |
423 Profile* GetProfileForNewWindows(); | |
424 | |
425 // Invoked when the associated browser or app is closed. | |
426 void LauncherItemClosed(ash::LauncherID id); | |
427 | |
428 // Internal helpers for pinning and unpinning that handle both | |
429 // client-triggered and internal pinning operations. | |
430 void DoPinAppWithID(const std::string& app_id); | |
431 void DoUnpinAppsWithID(const std::string& app_id); | |
432 | |
433 // Re-syncs launcher model with prefs::kPinnedLauncherApps. | |
434 void UpdateAppLaunchersFromPref(); | |
435 | |
436 // Persists the shelf auto-hide behavior to prefs. | |
437 void SetShelfAutoHideBehaviorPrefs(ash::ShelfAutoHideBehavior behavior, | |
438 aura::RootWindow* root_window); | |
439 | |
440 // Sets the shelf auto-hide behavior from prefs. | |
441 void SetShelfAutoHideBehaviorFromPrefs(); | |
442 | |
443 // Sets the shelf alignment from prefs. | |
444 void SetShelfAlignmentFromPrefs(); | |
445 | |
446 // Sets both of auto-hide behavior and alignment from prefs. | |
447 void SetShelfBehaviorsFromPrefs(); | |
448 | |
449 // Returns the most recently active web contents for an app. | |
450 content::WebContents* GetLastActiveWebContents(const std::string& app_id); | |
451 | |
452 // Creates an app launcher to insert at |index|. Note that |index| may be | |
453 // adjusted by the model to meet ordering constraints. | |
454 // The |launcher_item_type| will be set into the LauncherModel. | |
455 ash::LauncherID InsertAppLauncherItem( | |
456 LauncherItemController* controller, | |
457 const std::string& app_id, | |
458 ash::LauncherItemStatus status, | |
459 int index, | |
460 ash::LauncherItemType launcher_item_type); | |
461 | |
462 bool HasItemController(ash::LauncherID id) const; | |
463 | |
464 // Enumerate all Web contents which match a given shortcut |controller|. | |
465 std::vector<content::WebContents*> GetV1ApplicationsFromController( | |
466 LauncherItemController* controller); | |
467 | |
468 // Create LauncherItem for Browser Shortcut. | |
469 ash::LauncherID CreateBrowserShortcutLauncherItem(); | |
470 | |
471 // Check if the given |web_contents| is in incognito mode. | |
472 bool IsIncognito(content::WebContents* web_contents) const; | |
473 | |
474 // Update browser shortcut's index. | |
475 void PersistChromeItemIndex(int index); | |
476 | |
477 // Get browser shortcut's index from pref. | |
478 int GetChromeIconIndexFromPref() const; | |
479 | |
480 // Close all windowed V1 applications of a certain extension which was already | |
481 // deleted. | |
482 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id); | |
483 | |
484 // Move a launcher item ignoring the pinned state changes from |index| to | |
485 // |target_index|. | |
486 void MoveItemWithoutPinnedStateChangeNotification(int source_index, | |
487 int target_index); | |
488 | |
307 static ChromeLauncherController* instance_; | 489 static ChromeLauncherController* instance_; |
490 | |
491 ash::LauncherModel* model_; | |
492 | |
493 // Profile used for prefs and loading extensions. This is NOT necessarily the | |
494 // profile new windows are created with. | |
495 Profile* profile_; | |
496 | |
497 IDToItemControllerMap id_to_item_controller_map_; | |
498 | |
499 // Maintains activation order of web contents for each app. | |
500 AppIDToWebContentsListMap app_id_to_web_contents_list_; | |
501 | |
502 // Direct access to app_id for a web contents. | |
503 WebContentsToAppIDMap web_contents_to_app_id_; | |
504 | |
505 // Used to track shell windows. | |
506 scoped_ptr<ShellWindowLauncherController> shell_window_controller_; | |
507 | |
508 // Used to get app info for tabs. | |
509 scoped_ptr<AppTabHelper> app_tab_helper_; | |
510 | |
511 // Used to load the image for an app item. | |
512 scoped_ptr<extensions::AppIconLoader> app_icon_loader_; | |
513 | |
514 content::NotificationRegistrar notification_registrar_; | |
515 | |
516 PrefChangeRegistrar pref_change_registrar_; | |
517 | |
518 AppSyncUIState* app_sync_ui_state_; | |
519 | |
520 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; | |
521 | |
522 // Launchers that are currently being observed. | |
523 std::set<ash::Launcher*> launchers_; | |
524 | |
525 // The owned browser shortcut item. | |
526 scoped_ptr<BrowserShortcutLauncherItemController> browser_item_controller_; | |
527 | |
528 // If true, incoming pinned state changes should be ignored. | |
529 bool ignore_persist_pinned_state_change_; | |
530 | |
531 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); | |
308 }; | 532 }; |
309 | 533 |
310 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 534 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
OLD | NEW |