OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 public ash::ShelfModelObserver, | 94 public ash::ShelfModelObserver, |
95 public ash::ShellObserver, | 95 public ash::ShellObserver, |
96 public ash::DisplayController::Observer, | 96 public ash::DisplayController::Observer, |
97 public content::NotificationObserver, | 97 public content::NotificationObserver, |
98 public extensions::AppIconLoader::Delegate, | 98 public extensions::AppIconLoader::Delegate, |
99 public PrefServiceSyncableObserver, | 99 public PrefServiceSyncableObserver, |
100 public AppSyncUIStateObserver, | 100 public AppSyncUIStateObserver, |
101 public ExtensionEnableFlowDelegate, | 101 public ExtensionEnableFlowDelegate, |
102 public ash::ShelfLayoutManagerObserver { | 102 public ash::ShelfLayoutManagerObserver { |
103 public: | 103 public: |
104 // Indicates if a launcher item is incognito or not. | 104 // Indicates if a shelf item is incognito or not. |
105 enum IncognitoState { | 105 enum IncognitoState { |
106 STATE_INCOGNITO, | 106 STATE_INCOGNITO, |
107 STATE_NOT_INCOGNITO, | 107 STATE_NOT_INCOGNITO, |
108 }; | 108 }; |
109 | 109 |
110 // Used to update the state of non plaform apps, as web contents change. | 110 // Used to update the state of non plaform apps, as web contents change. |
111 enum AppState { | 111 enum AppState { |
112 APP_STATE_ACTIVE, | 112 APP_STATE_ACTIVE, |
113 APP_STATE_WINDOW_ACTIVE, | 113 APP_STATE_WINDOW_ACTIVE, |
114 APP_STATE_INACTIVE, | 114 APP_STATE_INACTIVE, |
(...skipping 25 matching lines...) Expand all Loading... | |
140 // Initializes this ChromeLauncherController. | 140 // Initializes this ChromeLauncherController. |
141 void Init(); | 141 void Init(); |
142 | 142 |
143 // Creates an instance. | 143 // Creates an instance. |
144 static ChromeLauncherController* CreateInstance(Profile* profile, | 144 static ChromeLauncherController* CreateInstance(Profile* profile, |
145 ash::ShelfModel* model); | 145 ash::ShelfModel* model); |
146 | 146 |
147 // Returns the single ChromeLauncherController instance. | 147 // Returns the single ChromeLauncherController instance. |
148 static ChromeLauncherController* instance() { return instance_; } | 148 static ChromeLauncherController* instance() { return instance_; } |
149 | 149 |
150 // Creates a new app item on the launcher for |controller|. | 150 // Creates a new app item on the shelf for |controller|. |
151 ash::LauncherID CreateAppLauncherItem(LauncherItemController* controller, | 151 ash::LauncherID CreateAppLauncherItem(LauncherItemController* controller, |
152 const std::string& app_id, | 152 const std::string& app_id, |
153 ash::LauncherItemStatus status); | 153 ash::LauncherItemStatus status); |
154 | 154 |
155 // Updates the running status of an item. It will also update the status of | 155 // Updates the running status of an item. It will also update the status of |
156 // browsers launcher item if needed. | 156 // browsers shelf item if needed. |
157 void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); | 157 void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); |
158 | 158 |
159 // Updates the controller associated with id (which should be a shortcut). | 159 // Updates the controller associated with id (which should be a shortcut). |
160 // |controller| remains owned by caller. | 160 // |controller| remains owned by caller. |
161 void SetItemController(ash::LauncherID id, | 161 void SetItemController(ash::LauncherID id, |
162 LauncherItemController* controller); | 162 LauncherItemController* controller); |
163 | 163 |
164 // Closes or unpins the launcher item. | 164 // Closes or unpins the shelf item. |
165 void CloseLauncherItem(ash::LauncherID id); | 165 void CloseLauncherItem(ash::LauncherID id); |
166 | 166 |
167 // Pins the specified id. Currently only supports platform apps. | 167 // Pins the specified id. Currently only supports platform apps. |
168 void Pin(ash::LauncherID id); | 168 void Pin(ash::LauncherID id); |
169 | 169 |
170 // Unpins the specified id, closing if not running. | 170 // Unpins the specified id, closing if not running. |
171 void Unpin(ash::LauncherID id); | 171 void Unpin(ash::LauncherID id); |
172 | 172 |
173 // Returns true if the item identified by |id| is pinned. | 173 // Returns true if the item identified by |id| is pinned. |
174 bool IsPinned(ash::LauncherID id); | 174 bool IsPinned(ash::LauncherID id); |
175 | 175 |
176 // Pins/unpins the specified id. | 176 // Pins/unpins the specified id. |
177 void TogglePinned(ash::LauncherID id); | 177 void TogglePinned(ash::LauncherID id); |
178 | 178 |
179 // Returns true if the specified item can be pinned or unpinned. Only apps can | 179 // Returns true if the specified item can be pinned or unpinned. Only apps can |
180 // be pinned. | 180 // be pinned. |
181 bool IsPinnable(ash::LauncherID id) const; | 181 bool IsPinnable(ash::LauncherID id) const; |
182 | 182 |
183 // If there is no launcher item in the launcher for application |app_id|, one | 183 // If there is no shelf item in the shelf for application |app_id|, one |
184 // gets created. The (existing or created) launcher items get then locked | 184 // gets created. The (existing or created) shelf items get then locked |
185 // against a users un-pinning removal. | 185 // against a users un-pinning removal. |
186 void LockV1AppWithID(const std::string& app_id); | 186 void LockV1AppWithID(const std::string& app_id); |
187 | 187 |
188 // A previously locked launcher item of type |app_id| gets unlocked. If the | 188 // A previously locked shelf item of type |app_id| gets unlocked. If the |
189 // lock count reaches 0 and the item is not pinned it will go away. | 189 // lock count reaches 0 and the item is not pinned it will go away. |
190 void UnlockV1AppWithID(const std::string& app_id); | 190 void UnlockV1AppWithID(const std::string& app_id); |
191 | 191 |
192 // Requests that the launcher item controller specified by |id| open a new | 192 // Requests that the shelf item controller specified by |id| open a new |
193 // instance of the app. |event_flags| holds the flags of the event which | 193 // instance of the app. |event_flags| holds the flags of the event which |
194 // triggered this command. | 194 // triggered this command. |
195 void Launch(ash::LauncherID id, int event_flags); | 195 void Launch(ash::LauncherID id, int event_flags); |
196 | 196 |
197 // Closes the specified item. | 197 // Closes the specified item. |
198 void Close(ash::LauncherID id); | 198 void Close(ash::LauncherID id); |
199 | 199 |
200 // Returns true if the specified item is open. | 200 // Returns true if the specified item is open. |
201 bool IsOpen(ash::LauncherID id); | 201 bool IsOpen(ash::LauncherID id); |
202 | 202 |
203 // Returns true if the specified item is for a platform app. | 203 // Returns true if the specified item is for a platform app. |
204 bool IsPlatformApp(ash::LauncherID id); | 204 bool IsPlatformApp(ash::LauncherID id); |
205 | 205 |
206 // Opens a new instance of the application identified by |app_id|. | 206 // Opens a new instance of the application identified by |app_id|. |
207 // Used by the app-list, and by pinned-app launcher items. | 207 // Used by the app-list, and by pinned-app shelf items. |
208 void LaunchApp(const std::string& app_id, | 208 void LaunchApp(const std::string& app_id, |
209 ash::LaunchSource source, | 209 ash::LaunchSource source, |
210 int event_flags); | 210 int event_flags); |
211 | 211 |
212 // If |app_id| is running, reactivates the app's most recently active window, | 212 // If |app_id| is running, reactivates the app's most recently active window, |
213 // otherwise launches and activates the app. | 213 // otherwise launches and activates the app. |
214 // Used by the app-list, and by pinned-app launcher items. | 214 // Used by the app-list, and by pinned-app shelf items. |
215 void ActivateApp(const std::string& app_id, | 215 void ActivateApp(const std::string& app_id, |
216 ash::LaunchSource source, | 216 ash::LaunchSource source, |
217 int event_flags); | 217 int event_flags); |
218 | 218 |
219 // Returns the launch type of app for the specified id. | 219 // Returns the launch type of app for the specified id. |
220 extensions::LaunchType GetLaunchType(ash::LauncherID id); | 220 extensions::LaunchType GetLaunchType(ash::LauncherID id); |
221 | 221 |
222 // Set the image for a specific launcher item (e.g. when set by the app). | 222 // Set the image for a specific shelf item (e.g. when set by the app). |
223 void SetLauncherItemImage(ash::LauncherID launcher_id, | 223 void SetLauncherItemImage(ash::LauncherID launcher_id, |
224 const gfx::ImageSkia& image); | 224 const gfx::ImageSkia& image); |
225 | 225 |
226 // Find out if the given application |id| is a windowed app item and not a | 226 // Find out if the given application |id| is a windowed app item and not a |
227 // pinned item in the launcher. | 227 // pinned item in the shelf. |
228 bool IsWindowedAppInLauncher(const std::string& app_id); | 228 bool IsWindowedAppInLauncher(const std::string& app_id); |
229 | 229 |
230 // Updates the launch type of the app for the specified id to |launch_type|. | 230 // Updates the launch type of the app for the specified id to |launch_type|. |
231 void SetLaunchType(ash::LauncherID id, | 231 void SetLaunchType(ash::LauncherID id, |
232 extensions::LaunchType launch_type); | 232 extensions::LaunchType launch_type); |
233 | 233 |
234 // Returns true if the user is currently logged in as a guest. | 234 // Returns true if the user is currently logged in as a guest. |
235 // Makes virtual for unittest in LauncherContextMenuTest. | 235 // Makes virtual for unittest in LauncherContextMenuTest. |
236 virtual bool IsLoggedInAsGuest(); | 236 virtual bool IsLoggedInAsGuest(); |
237 | 237 |
238 // Invoked when user clicks on button in the launcher and there is no last | 238 // Invoked when user clicks on button in the shelf and there is no last |
239 // used window (or CTRL is held with the click). | 239 // used window (or CTRL is held with the click). |
240 void CreateNewWindow(); | 240 void CreateNewWindow(); |
241 | 241 |
242 // Invoked when the user clicks on button in the launcher to create a new | 242 // Invoked when the user clicks on button in the shelf to create a new |
243 // incognito window. | 243 // incognito window. |
244 void CreateNewIncognitoWindow(); | 244 void CreateNewIncognitoWindow(); |
245 | 245 |
246 // 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. |
247 // 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 |
248 // id of the app. | 248 // id of the app. |
249 void PersistPinnedState(); | 249 void PersistPinnedState(); |
250 | 250 |
251 ash::ShelfModel* model(); | 251 ash::ShelfModel* model(); |
252 | 252 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 // Returns the extension identified by |app_id|. | 284 // Returns the extension identified by |app_id|. |
285 const extensions::Extension* GetExtensionForAppID( | 285 const extensions::Extension* GetExtensionForAppID( |
286 const std::string& app_id) const; | 286 const std::string& app_id) const; |
287 | 287 |
288 // Activates a |window|. If |allow_minimize| is true and the system allows | 288 // Activates a |window|. If |allow_minimize| is true and the system allows |
289 // it, the the window will get minimized instead. | 289 // it, the the window will get minimized instead. |
290 void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, | 290 void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, |
291 bool allow_minimize); | 291 bool allow_minimize); |
292 | 292 |
293 // ash::ShelfDelegate overrides: | 293 // ash::ShelfDelegate overrides: |
294 virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; | 294 virtual void OnShelfCreated(ash::Shelf* shelf) OVERRIDE; |
295 virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE; | 295 virtual void OnShelfDestroyed(ash::Shelf* shelf) OVERRIDE; |
296 virtual ash::LauncherID GetLauncherIDForAppID( | 296 virtual ash::LauncherID GetLauncherIDForAppID( |
297 const std::string& app_id) OVERRIDE; | 297 const std::string& app_id) OVERRIDE; |
298 virtual const std::string& GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE; | 298 virtual const std::string& GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE; |
299 virtual void PinAppWithID(const std::string& app_id) OVERRIDE; | 299 virtual void PinAppWithID(const std::string& app_id) OVERRIDE; |
300 virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; | 300 virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; |
301 virtual bool CanPin() const OVERRIDE; | 301 virtual bool CanPin() const OVERRIDE; |
302 virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE; | 302 virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE; |
303 | 303 |
304 // ash::ShelfModelObserver overrides: | 304 // ash::ShelfModelObserver overrides: |
305 virtual void ShelfItemAdded(int index) OVERRIDE; | 305 virtual void ShelfItemAdded(int index) OVERRIDE; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 BrowserStatusMonitor* browser_status_monitor_for_test() { | 390 BrowserStatusMonitor* browser_status_monitor_for_test() { |
391 return browser_status_monitor_.get(); | 391 return browser_status_monitor_.get(); |
392 } | 392 } |
393 | 393 |
394 // Access to the ShellWindowController for tests. | 394 // Access to the ShellWindowController for tests. |
395 ShellWindowLauncherController* shell_window_controller_for_test() { | 395 ShellWindowLauncherController* shell_window_controller_for_test() { |
396 return shell_window_controller_.get(); | 396 return shell_window_controller_.get(); |
397 } | 397 } |
398 | 398 |
399 protected: | 399 protected: |
400 // Creates a new app shortcut item and controller on the launcher at |index|. | 400 // Creates a new app shortcut item and controller on the shelf at |index|. |
401 // Use kInsertItemAtEnd to add a shortcut as the last item. | 401 // Use kInsertItemAtEnd to add a shortcut as the last item. |
402 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& app_id, | 402 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& app_id, |
403 int index); | 403 int index); |
404 | 404 |
405 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. | 405 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. |
406 // These are intended for testing. | 406 // These are intended for testing. |
407 void SetAppTabHelperForTest(AppTabHelper* helper); | 407 void SetAppTabHelperForTest(AppTabHelper* helper); |
408 void SetAppIconLoaderForTest(extensions::AppIconLoader* loader); | 408 void SetAppIconLoaderForTest(extensions::AppIconLoader* loader); |
409 const std::string& GetAppIdFromLauncherIdForTest(ash::LauncherID id); | 409 const std::string& GetAppIdFromLauncherIdForTest(ash::LauncherID id); |
410 | 410 |
411 // Sets the ash::ShelfItemDelegateManager only for unittests and doesn't | 411 // Sets the ash::ShelfItemDelegateManager only for unittests and doesn't |
412 // take an ownership of it. | 412 // take an ownership of it. |
413 void SetShelfItemDelegateManagerForTest( | 413 void SetShelfItemDelegateManagerForTest( |
414 ash::ShelfItemDelegateManager* manager); | 414 ash::ShelfItemDelegateManager* manager); |
415 | 415 |
416 private: | 416 private: |
417 friend class ChromeLauncherControllerTest; | 417 friend class ChromeLauncherControllerTest; |
418 friend class LauncherAppBrowserTest; | 418 friend class LauncherAppBrowserTest; |
419 friend class LauncherPlatformAppBrowserTest; | 419 friend class LauncherPlatformAppBrowserTest; |
420 | 420 |
421 typedef std::map<ash::LauncherID, LauncherItemController*> | 421 typedef std::map<ash::LauncherID, LauncherItemController*> |
422 IDToItemControllerMap; | 422 IDToItemControllerMap; |
423 typedef std::list<content::WebContents*> WebContentsList; | 423 typedef std::list<content::WebContents*> WebContentsList; |
424 typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; | 424 typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; |
425 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; | 425 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; |
426 | 426 |
427 // Creates a new app shortcut item and controller on the launcher at |index|. | 427 // Creates a new app shortcut item and controller on the shelf at |index|. |
428 // Use kInsertItemAtEnd to add a shortcut as the last item. | 428 // Use kInsertItemAtEnd to add a shortcut as the last item. |
429 ash::LauncherID CreateAppShortcutLauncherItemWithType( | 429 ash::LauncherID CreateAppShortcutLauncherItemWithType( |
430 const std::string& app_id, | 430 const std::string& app_id, |
431 int index, | 431 int index, |
432 ash::LauncherItemType launcher_item_type); | 432 ash::LauncherItemType launcher_item_type); |
433 | 433 |
434 // Invoked when the associated browser or app is closed. | 434 // Invoked when the associated browser or app is closed. |
435 void LauncherItemClosed(ash::LauncherID id); | 435 void LauncherItemClosed(ash::LauncherID id); |
436 | 436 |
437 // Internal helpers for pinning and unpinning that handle both | 437 // Internal helpers for pinning and unpinning that handle both |
438 // client-triggered and internal pinning operations. | 438 // client-triggered and internal pinning operations. |
439 void DoPinAppWithID(const std::string& app_id); | 439 void DoPinAppWithID(const std::string& app_id); |
440 void DoUnpinAppWithID(const std::string& app_id); | 440 void DoUnpinAppWithID(const std::string& app_id); |
441 | 441 |
442 // Pin a running app with |launcher_id| internally to |index|. It returns | 442 // Pin a running app with |launcher_id| internally to |index|. It returns |
443 // the index where the item was pinned. | 443 // the index where the item was pinned. |
444 int PinRunningAppInternal(int index, ash::LauncherID launcher_id); | 444 int PinRunningAppInternal(int index, ash::LauncherID launcher_id); |
445 | 445 |
446 // Unpin a locked application. This is an internal call which converts the | 446 // Unpin a locked application. This is an internal call which converts the |
447 // model type of the given app index from a shortcut into an unpinned running | 447 // model type of the given app index from a shortcut into an unpinned running |
448 // app. | 448 // app. |
449 void UnpinRunningAppInternal(int index); | 449 void UnpinRunningAppInternal(int index); |
450 | 450 |
451 // Re-syncs launcher model with prefs::kPinnedLauncherApps. | 451 // Re-syncs shelf model with prefs::kPinnedLauncherApps. |
452 void UpdateAppLaunchersFromPref(); | 452 void UpdateAppLaunchersFromPref(); |
453 | 453 |
454 // Persists the shelf auto-hide behavior to prefs. | 454 // Persists the shelf auto-hide behavior to prefs. |
455 void SetShelfAutoHideBehaviorPrefs(ash::ShelfAutoHideBehavior behavior, | 455 void SetShelfAutoHideBehaviorPrefs(ash::ShelfAutoHideBehavior behavior, |
456 aura::Window* root_window); | 456 aura::Window* root_window); |
457 | 457 |
458 // Sets the shelf auto-hide behavior from prefs. | 458 // Sets the shelf auto-hide behavior from prefs. |
459 void SetShelfAutoHideBehaviorFromPrefs(); | 459 void SetShelfAutoHideBehaviorFromPrefs(); |
460 | 460 |
461 // Sets the shelf alignment from prefs. | 461 // Sets the shelf alignment from prefs. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 scoped_ptr<extensions::AppIconLoader> app_icon_loader_; | 565 scoped_ptr<extensions::AppIconLoader> app_icon_loader_; |
566 | 566 |
567 content::NotificationRegistrar notification_registrar_; | 567 content::NotificationRegistrar notification_registrar_; |
568 | 568 |
569 PrefChangeRegistrar pref_change_registrar_; | 569 PrefChangeRegistrar pref_change_registrar_; |
570 | 570 |
571 AppSyncUIState* app_sync_ui_state_; | 571 AppSyncUIState* app_sync_ui_state_; |
572 | 572 |
573 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; | 573 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; |
574 | 574 |
575 // Launchers that are currently being observed. | 575 // Shelfs that are currently being observed. |
576 std::set<ash::Launcher*> launchers_; | 576 std::set<ash::Shelf*> shelfs_; |
James Cook
2013/12/16 23:34:52
nit: shelfs_ -> shelves_. English is such a weird
tfarina
2013/12/17 00:45:24
Done.
| |
577 | 577 |
578 // The owned browser status monitor. | 578 // The owned browser status monitor. |
579 scoped_ptr<BrowserStatusMonitor> browser_status_monitor_; | 579 scoped_ptr<BrowserStatusMonitor> browser_status_monitor_; |
580 | 580 |
581 // A special observer class to detect user switches. | 581 // A special observer class to detect user switches. |
582 scoped_ptr<ChromeLauncherControllerUserSwitchObserver> user_switch_observer_; | 582 scoped_ptr<ChromeLauncherControllerUserSwitchObserver> user_switch_observer_; |
583 | 583 |
584 // If true, incoming pinned state changes should be ignored. | 584 // If true, incoming pinned state changes should be ignored. |
585 bool ignore_persist_pinned_state_change_; | 585 bool ignore_persist_pinned_state_change_; |
586 | 586 |
587 // True if each user has an own desktop. | 587 // True if each user has an own desktop. |
588 bool multi_profile_desktop_separation_; | 588 bool multi_profile_desktop_separation_; |
589 | 589 |
590 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); | 590 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
591 }; | 591 }; |
592 | 592 |
593 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 593 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
OLD | NEW |