| 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_IMPL_H_ |
| 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | |
| 10 #include <memory> | 9 #include <memory> |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | 10 |
| 14 #include "ash/common/shelf/shelf_item_delegate.h" | |
| 15 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 11 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
| 16 #include "ash/common/shelf/shelf_item_types.h" | |
| 17 #include "ash/common/shelf/shelf_model_observer.h" | 12 #include "ash/common/shelf/shelf_model_observer.h" |
| 18 #include "ash/common/shelf/shelf_types.h" | 13 #include "ash/common/shelf/shelf_types.h" |
| 19 #include "ash/display/window_tree_host_manager.h" | 14 #include "ash/display/window_tree_host_manager.h" |
| 20 #include "ash/shelf/shelf_delegate.h" | 15 #include "ash/shelf/shelf_delegate.h" |
| 21 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 22 #include "base/macros.h" | 17 #include "base/macros.h" |
| 23 #include "base/memory/scoped_vector.h" | |
| 24 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 25 #include "chrome/browser/ui/app_icon_loader.h" | 19 #include "chrome/browser/ui/app_icon_loader.h" |
| 26 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | |
| 27 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" | 20 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
| 28 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 21 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" | |
| 30 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" | 22 #include "chrome/browser/ui/ash/launcher/launcher_app_updater.h" |
| 31 #include "components/prefs/pref_change_registrar.h" | 23 #include "components/prefs/pref_change_registrar.h" |
| 32 #include "extensions/common/constants.h" | |
| 33 #include "ui/aura/window_observer.h" | 24 #include "ui/aura/window_observer.h" |
| 34 | 25 |
| 35 class AppSyncUIState; | 26 class AppSyncUIState; |
| 36 class ArcAppDeferredLauncherController; | |
| 37 class Browser; | |
| 38 class BrowserShortcutLauncherItemController; | |
| 39 class BrowserStatusMonitor; | 27 class BrowserStatusMonitor; |
| 40 class GURL; | |
| 41 class LauncherControllerHelper; | 28 class LauncherControllerHelper; |
| 42 class LauncherItemController; | |
| 43 class Profile; | 29 class Profile; |
| 44 class AppWindowLauncherController; | 30 class AppWindowLauncherController; |
| 45 class TabContents; | 31 class TabContents; |
| 46 | 32 |
| 47 namespace ash { | 33 namespace ash { |
| 48 class ChromeLauncherPrefsObserver; | 34 class ChromeLauncherPrefsObserver; |
| 49 class ShelfItemDelegateManager; | 35 class ShelfItemDelegateManager; |
| 50 class ShelfModel; | 36 class ShelfModel; |
| 51 } | 37 } |
| 52 | 38 |
| 53 namespace aura { | 39 namespace aura { |
| 54 class Window; | 40 class Window; |
| 55 } | 41 } |
| 56 | 42 |
| 57 namespace content { | 43 namespace content { |
| 58 class BrowserContext; | 44 class BrowserContext; |
| 59 class WebContents; | |
| 60 } | 45 } |
| 61 | 46 |
| 62 namespace extensions { | 47 namespace extensions { |
| 63 class Extension; | 48 class Extension; |
| 64 } | 49 } |
| 65 | 50 |
| 66 namespace ui { | |
| 67 class BaseWindow; | |
| 68 } | |
| 69 | |
| 70 class ChromeLauncherControllerUserSwitchObserver; | 51 class ChromeLauncherControllerUserSwitchObserver; |
| 71 | 52 |
| 72 // A list of the elements which makes up a simple menu description. | 53 // Implementation of ChromeLauncherController, used for classic Ash. |
| 73 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; | 54 // In addition to implementing ChromeLauncherController, this class performs |
| 74 | 55 // a lot of other responsibilities, such as implementing ash::ShelfDelegate, |
| 75 // ChromeLauncherController manages the launcher items needed for content | 56 // updating the UI state and the shelf model when apps are uninstalled, etc. |
| 76 // windows. Launcher items have a type, an optional app id, and a controller. | 57 class ChromeLauncherControllerImpl |
| 77 // This incarnation groups running tabs/windows in application specific lists. | 58 : public ChromeLauncherController, |
| 78 // * Browser app windows have BrowserShortcutLauncherItemController, owned by | 59 public ash::ShelfDelegate, |
| 79 // the BrowserView instance. | |
| 80 // * App windows have AppWindowLauncherItemController, owned by | |
| 81 // AppWindowLauncherController. | |
| 82 // * Shortcuts have no LauncherItemController. | |
| 83 class ChromeLauncherController | |
| 84 : public ash::ShelfDelegate, | |
| 85 public ash::ShelfModelObserver, | 60 public ash::ShelfModelObserver, |
| 86 public ash::WindowTreeHostManager::Observer, | 61 public ash::WindowTreeHostManager::Observer, |
| 87 public AppIconLoaderDelegate, | 62 public AppIconLoaderDelegate, |
| 88 public AppSyncUIStateObserver, | 63 public AppSyncUIStateObserver, |
| 89 public LauncherAppUpdater::Delegate, | 64 public LauncherAppUpdater::Delegate, |
| 90 public ash::ShelfItemDelegateManagerObserver { | 65 public ash::ShelfItemDelegateManagerObserver { |
| 91 public: | 66 public: |
| 92 // Used to update the state of non plaform apps, as web contents change. | 67 ChromeLauncherControllerImpl(Profile* profile, ash::ShelfModel* model); |
| 93 enum AppState { | 68 ~ChromeLauncherControllerImpl() override; |
| 94 APP_STATE_ACTIVE, | |
| 95 APP_STATE_WINDOW_ACTIVE, | |
| 96 APP_STATE_INACTIVE, | |
| 97 APP_STATE_REMOVED | |
| 98 }; | |
| 99 | 69 |
| 100 ChromeLauncherController(Profile* profile, ash::ShelfModel* model); | 70 // Create ChromeLauncherControllerImpl instance and set is as the |
| 101 ~ChromeLauncherController() override; | 71 // ChromeLauncherController singleton. |
| 72 static ChromeLauncherControllerImpl* CreateInstance(Profile* profile, |
| 73 ash::ShelfModel* model); |
| 102 | 74 |
| 103 // Initializes this ChromeLauncherController. | 75 // ChromeLauncherController: |
| 104 void Init(); | 76 void Init() override; |
| 105 | |
| 106 // Creates an instance. | |
| 107 static ChromeLauncherController* CreateInstance(Profile* profile, | |
| 108 ash::ShelfModel* model); | |
| 109 | |
| 110 // Returns the single ChromeLauncherController instance. | |
| 111 static ChromeLauncherController* instance() { return instance_; } | |
| 112 | |
| 113 // Creates a new app item on the shelf for |controller|. | |
| 114 ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, | 77 ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, |
| 115 const std::string& app_id, | 78 const std::string& app_id, |
| 116 ash::ShelfItemStatus status); | 79 ash::ShelfItemStatus status) override; |
| 117 | 80 void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status) override; |
| 118 // Updates the running status of an item. It will also update the status of | 81 void SetItemController(ash::ShelfID id, |
| 119 // browsers shelf item if needed. | 82 LauncherItemController* controller) override; |
| 120 void SetItemStatus(ash::ShelfID id, ash::ShelfItemStatus status); | 83 void CloseLauncherItem(ash::ShelfID id) override; |
| 121 | 84 void Pin(ash::ShelfID id) override; |
| 122 // Updates the controller associated with id (which should be a shortcut). | 85 void Unpin(ash::ShelfID id) override; |
| 123 // |controller| will be owned by the |ChromeLauncherController| and then | 86 bool IsPinned(ash::ShelfID id) override; |
| 124 // passed on to |ShelfItemDelegateManager|. | 87 void TogglePinned(ash::ShelfID id) override; |
| 125 // TODO(skuhne): Pass in scoped_ptr to make ownership clear. | 88 bool IsPinnable(ash::ShelfID id) const override; |
| 126 void SetItemController(ash::ShelfID id, LauncherItemController* controller); | 89 void LockV1AppWithID(const std::string& app_id) override; |
| 127 | 90 void UnlockV1AppWithID(const std::string& app_id) override; |
| 128 // Closes or unpins the shelf item. | 91 void Launch(ash::ShelfID id, int event_flags) override; |
| 129 void CloseLauncherItem(ash::ShelfID id); | 92 void Close(ash::ShelfID id) override; |
| 130 | 93 bool IsOpen(ash::ShelfID id) override; |
| 131 // Pins the specified id. Currently only supports platform apps. | 94 bool IsPlatformApp(ash::ShelfID id) override; |
| 132 void Pin(ash::ShelfID id); | |
| 133 | |
| 134 // Unpins the specified id, closing if not running. | |
| 135 void Unpin(ash::ShelfID id); | |
| 136 | |
| 137 // Returns true if the item identified by |id| is pinned. | |
| 138 bool IsPinned(ash::ShelfID id); | |
| 139 | |
| 140 // Pins/unpins the specified id. | |
| 141 void TogglePinned(ash::ShelfID id); | |
| 142 | |
| 143 // Returns true if the specified item can be pinned or unpinned. Only apps can | |
| 144 // be pinned. | |
| 145 bool IsPinnable(ash::ShelfID id) const; | |
| 146 | |
| 147 // If there is no shelf item in the shelf for application |app_id|, one | |
| 148 // gets created. The (existing or created) shelf items get then locked | |
| 149 // against a users un-pinning removal. | |
| 150 void LockV1AppWithID(const std::string& app_id); | |
| 151 | |
| 152 // A previously locked shelf item of type |app_id| gets unlocked. If the | |
| 153 // lock count reaches 0 and the item is not pinned it will go away. | |
| 154 void UnlockV1AppWithID(const std::string& app_id); | |
| 155 | |
| 156 // Requests that the shelf item controller specified by |id| open a new | |
| 157 // instance of the app. |event_flags| holds the flags of the event which | |
| 158 // triggered this command. | |
| 159 void Launch(ash::ShelfID id, int event_flags); | |
| 160 | |
| 161 // Closes the specified item. | |
| 162 void Close(ash::ShelfID id); | |
| 163 | |
| 164 // Returns true if the specified item is open. | |
| 165 bool IsOpen(ash::ShelfID id); | |
| 166 | |
| 167 // Returns true if the specified item is for a platform app. | |
| 168 bool IsPlatformApp(ash::ShelfID id); | |
| 169 | |
| 170 // Opens a new instance of the application identified by |app_id|. | |
| 171 // Used by the app-list, and by pinned-app shelf items. | |
| 172 void LaunchApp(const std::string& app_id, | 95 void LaunchApp(const std::string& app_id, |
| 173 ash::LaunchSource source, | 96 ash::LaunchSource source, |
| 174 int event_flags); | 97 int event_flags) override; |
| 175 | |
| 176 // If |app_id| is running, reactivates the app's most recently active window, | |
| 177 // otherwise launches and activates the app. | |
| 178 // Used by the app-list, and by pinned-app shelf items. | |
| 179 void ActivateApp(const std::string& app_id, | 98 void ActivateApp(const std::string& app_id, |
| 180 ash::LaunchSource source, | 99 ash::LaunchSource source, |
| 181 int event_flags); | 100 int event_flags) override; |
| 182 | 101 extensions::LaunchType GetLaunchType(ash::ShelfID id) override; |
| 183 // Returns the launch type of app for the specified id. | 102 void SetLauncherItemImage(ash::ShelfID shelf_id, |
| 184 extensions::LaunchType GetLaunchType(ash::ShelfID id); | 103 const gfx::ImageSkia& image) override; |
| 185 | 104 bool IsWindowedAppInLauncher(const std::string& app_id) override; |
| 186 // Set the image for a specific shelf item (e.g. when set by the app). | 105 void SetLaunchType(ash::ShelfID id, |
| 187 void SetLauncherItemImage(ash::ShelfID shelf_id, const gfx::ImageSkia& image); | 106 extensions::LaunchType launch_type) override; |
| 188 | 107 void PersistPinnedState() override; |
| 189 // Find out if the given application |id| is a windowed app item and not a | 108 Profile* GetProfile() override; |
| 190 // pinned item in the shelf. | 109 void UpdateAppState(content::WebContents* contents, |
| 191 bool IsWindowedAppInLauncher(const std::string& app_id); | 110 AppState app_state) override; |
| 192 | 111 ash::ShelfID GetShelfIDForWebContents( |
| 193 // Updates the launch type of the app for the specified id to |launch_type|. | 112 content::WebContents* contents) override; |
| 194 void SetLaunchType(ash::ShelfID id, extensions::LaunchType launch_type); | 113 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url) override; |
| 195 | |
| 196 // Updates the pinned pref state. The pinned state consists of a list pref. | |
| 197 // Each item of the list is a dictionary. The key |kAppIDPath| gives the | |
| 198 // id of the app. | |
| 199 void PersistPinnedState(); | |
| 200 | |
| 201 // Accessor to the currently loaded profile. Note that in multi profile use | |
| 202 // cases this might change over time. | |
| 203 Profile* profile(); | |
| 204 | |
| 205 // Notify the controller that the state of an non platform app's tabs | |
| 206 // have changed, | |
| 207 void UpdateAppState(content::WebContents* contents, AppState app_state); | |
| 208 | |
| 209 // Returns ShelfID for |contents|. If |contents| is not an app or is not | |
| 210 // pinned, returns the id of browser shrotcut. | |
| 211 ash::ShelfID GetShelfIDForWebContents(content::WebContents* contents); | |
| 212 | |
| 213 // Limits application refocusing to urls that match |url| for |id|. | |
| 214 void SetRefocusURLPatternForTest(ash::ShelfID id, const GURL& url); | |
| 215 | |
| 216 // Returns the extension identified by |app_id|. | |
| 217 const extensions::Extension* GetExtensionForAppID( | 114 const extensions::Extension* GetExtensionForAppID( |
| 218 const std::string& app_id) const; | 115 const std::string& app_id) const override; |
| 219 | |
| 220 // Activates a |window|. If |allow_minimize| is true and the system allows | |
| 221 // it, the the window will get minimized instead. | |
| 222 // Returns the action performed. Should be one of kNoAction, | |
| 223 // kExistingWindowActivated, or kExistingWindowMinimized. | |
| 224 ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive( | 116 ash::ShelfItemDelegate::PerformedAction ActivateWindowOrMinimizeIfActive( |
| 225 ui::BaseWindow* window, | 117 ui::BaseWindow* window, |
| 226 bool allow_minimize); | 118 bool allow_minimize) override; |
| 119 void ActiveUserChanged(const std::string& user_email) override; |
| 120 void AdditionalUserAddedToSession(Profile* profile) override; |
| 121 ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, |
| 122 int event_flags) override; |
| 123 std::vector<content::WebContents*> GetV1ApplicationsFromAppId( |
| 124 const std::string& app_id) override; |
| 125 void ActivateShellApp(const std::string& app_id, int index) override; |
| 126 bool IsWebContentHandledByApplication(content::WebContents* web_contents, |
| 127 const std::string& app_id) override; |
| 128 bool ContentCanBeHandledByGmailApp( |
| 129 content::WebContents* web_contents) override; |
| 130 gfx::Image GetAppListIcon(content::WebContents* web_contents) const override; |
| 131 base::string16 GetAppListTitle( |
| 132 content::WebContents* web_contents) const override; |
| 133 BrowserShortcutLauncherItemController* |
| 134 GetBrowserShortcutLauncherItemController() override; |
| 135 LauncherItemController* GetLauncherItemController( |
| 136 const ash::ShelfID id) override; |
| 137 bool IsBrowserFromActiveUser(Browser* browser) override; |
| 138 bool ShelfBoundsChangesProbablyWithUser( |
| 139 ash::Shelf* shelf, |
| 140 const std::string& user_id) const override; |
| 141 void OnUserProfileReadyToSwitch(Profile* profile) override; |
| 142 AppListControllerDelegate::Pinnable GetPinnable( |
| 143 const std::string& app_id) override; |
| 144 ArcAppDeferredLauncherController* GetArcDeferredLauncher() override; |
| 145 |
| 146 // Access to the BrowserStatusMonitor for tests. |
| 147 BrowserStatusMonitor* browser_status_monitor_for_test() { |
| 148 return browser_status_monitor_.get(); |
| 149 } |
| 150 |
| 151 // Access to the AppWindowLauncherController for tests. |
| 152 AppWindowLauncherController* app_window_controller_for_test() { |
| 153 return app_window_controllers_[0].get(); |
| 154 } |
| 227 | 155 |
| 228 // ash::ShelfDelegate: | 156 // ash::ShelfDelegate: |
| 229 void OnShelfCreated(ash::Shelf* shelf) override; | 157 void OnShelfCreated(ash::Shelf* shelf) override; |
| 230 void OnShelfDestroyed(ash::Shelf* shelf) override; | 158 void OnShelfDestroyed(ash::Shelf* shelf) override; |
| 231 void OnShelfAlignmentChanged(ash::Shelf* shelf) override; | 159 void OnShelfAlignmentChanged(ash::Shelf* shelf) override; |
| 232 void OnShelfAutoHideBehaviorChanged(ash::Shelf* shelf) override; | 160 void OnShelfAutoHideBehaviorChanged(ash::Shelf* shelf) override; |
| 233 void OnShelfAutoHideStateChanged(ash::Shelf* shelf) override; | 161 void OnShelfAutoHideStateChanged(ash::Shelf* shelf) override; |
| 234 void OnShelfVisibilityStateChanged(ash::Shelf* shelf) override; | 162 void OnShelfVisibilityStateChanged(ash::Shelf* shelf) override; |
| 235 ash::ShelfID GetShelfIDForAppID(const std::string& app_id) override; | 163 ash::ShelfID GetShelfIDForAppID(const std::string& app_id) override; |
| 236 bool HasShelfIDToAppIDMapping(ash::ShelfID id) const override; | 164 bool HasShelfIDToAppIDMapping(ash::ShelfID id) const override; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 261 void OnAppUninstalled(content::BrowserContext* browser_context, | 189 void OnAppUninstalled(content::BrowserContext* browser_context, |
| 262 const std::string& app_id) override; | 190 const std::string& app_id) override; |
| 263 | 191 |
| 264 // AppSyncUIStateObserver: | 192 // AppSyncUIStateObserver: |
| 265 void OnAppSyncUIStatusChanged() override; | 193 void OnAppSyncUIStatusChanged() override; |
| 266 | 194 |
| 267 // AppIconLoaderDelegate: | 195 // AppIconLoaderDelegate: |
| 268 void OnAppImageUpdated(const std::string& app_id, | 196 void OnAppImageUpdated(const std::string& app_id, |
| 269 const gfx::ImageSkia& image) override; | 197 const gfx::ImageSkia& image) override; |
| 270 | 198 |
| 271 // Called when the active user has changed. | |
| 272 void ActiveUserChanged(const std::string& user_email); | |
| 273 | 199 |
| 274 // Called when a user got added to the session. | |
| 275 void AdditionalUserAddedToSession(Profile* profile); | |
| 276 | |
| 277 // Get the list of all running incarnations of this item. | |
| 278 // |event_flags| specifies the flags which were set by the event which | |
| 279 // triggered this menu generation. It can be used to generate different lists. | |
| 280 ChromeLauncherAppMenuItems GetApplicationList(const ash::ShelfItem& item, | |
| 281 int event_flags); | |
| 282 | |
| 283 // Get the list of all tabs which belong to a certain application type. | |
| 284 std::vector<content::WebContents*> GetV1ApplicationsFromAppId( | |
| 285 const std::string& app_id); | |
| 286 | |
| 287 // Activates a specified shell application. | |
| 288 void ActivateShellApp(const std::string& app_id, int index); | |
| 289 | |
| 290 // Checks if a given |web_contents| is known to be associated with an | |
| 291 // application of type |app_id|. | |
| 292 bool IsWebContentHandledByApplication(content::WebContents* web_contents, | |
| 293 const std::string& app_id); | |
| 294 | |
| 295 // Check if the gMail app is loaded and it can handle the given web content. | |
| 296 // This special treatment is required to address crbug.com/234268. | |
| 297 bool ContentCanBeHandledByGmailApp(content::WebContents* web_contents); | |
| 298 | |
| 299 // Get the favicon for the application list entry for |web_contents|. | |
| 300 // Note that for incognito windows the incognito icon will be returned. | |
| 301 // If |web_contents| has not loaded, returns the default favicon. | |
| 302 gfx::Image GetAppListIcon(content::WebContents* web_contents) const; | |
| 303 | |
| 304 // Get the title for the applicatoin list entry for |web_contents|. | |
| 305 // If |web_contents| has not loaded, returns "Net Tab". | |
| 306 base::string16 GetAppListTitle(content::WebContents* web_contents) const; | |
| 307 | |
| 308 // Returns the LauncherItemController of BrowserShortcut. | |
| 309 BrowserShortcutLauncherItemController* | |
| 310 GetBrowserShortcutLauncherItemController(); | |
| 311 | |
| 312 LauncherItemController* GetLauncherItemController(const ash::ShelfID id); | |
| 313 | |
| 314 // Returns true if |browser| is owned by the active user. | |
| 315 bool IsBrowserFromActiveUser(Browser* browser); | |
| 316 | |
| 317 // Check if the shelf visibility (location, visibility) will change with a new | |
| 318 // user profile or not. However, since the full visibility calculation of the | |
| 319 // shelf cannot be performed here, this is only a probability used for | |
| 320 // animation predictions. | |
| 321 bool ShelfBoundsChangesProbablyWithUser(ash::Shelf* shelf, | |
| 322 const std::string& user_id) const; | |
| 323 | |
| 324 // Called when the user profile is fully loaded and ready to switch to. | |
| 325 void OnUserProfileReadyToSwitch(Profile* profile); | |
| 326 | |
| 327 // Access to the BrowserStatusMonitor for tests. | |
| 328 BrowserStatusMonitor* browser_status_monitor_for_test() { | |
| 329 return browser_status_monitor_.get(); | |
| 330 } | |
| 331 | |
| 332 // Access to the AppWindowLauncherController for tests. | |
| 333 AppWindowLauncherController* app_window_controller_for_test() { | |
| 334 return app_window_controllers_[0].get(); | |
| 335 } | |
| 336 | |
| 337 // Controller to launch Arc apps in deferred mode. | |
| 338 ArcAppDeferredLauncherController* arc_deferred_launcher() { | |
| 339 return arc_deferred_launcher_.get(); | |
| 340 } | |
| 341 | |
| 342 // TODO(khmel): Find better home for Pinnable enum. | |
| 343 AppListControllerDelegate::Pinnable GetPinnable(const std::string& app_id); | |
| 344 | 200 |
| 345 protected: | 201 protected: |
| 346 // Creates a new app shortcut item and controller on the shelf at |index|. | 202 // Creates a new app shortcut item and controller on the shelf at |index|. |
| 347 // Use kInsertItemAtEnd to add a shortcut as the last item. | 203 // Use kInsertItemAtEnd to add a shortcut as the last item. |
| 348 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& app_id, | 204 ash::ShelfID CreateAppShortcutLauncherItem(const std::string& app_id, |
| 349 int index); | 205 int index); |
| 350 | 206 |
| 351 // Sets LauncherControllerHelper/AppIconLoader for test, taking ownership. | 207 // Sets LauncherControllerHelper/AppIconLoader for test, taking ownership. |
| 352 void SetLauncherControllerHelperForTest(LauncherControllerHelper* helper); | 208 void SetLauncherControllerHelperForTest(LauncherControllerHelper* helper); |
| 353 void SetAppIconLoadersForTest( | 209 void SetAppIconLoadersForTest( |
| 354 std::vector<std::unique_ptr<AppIconLoader>>& loaders); | 210 std::vector<std::unique_ptr<AppIconLoader>>& loaders); |
| 355 const std::string& GetAppIdFromShelfIdForTest(ash::ShelfID id); | 211 const std::string& GetAppIdFromShelfIdForTest(ash::ShelfID id); |
| 356 | 212 |
| 357 // Sets the ash::ShelfItemDelegateManager only for unittests and doesn't | 213 // Sets the ash::ShelfItemDelegateManager only for unittests and doesn't |
| 358 // take an ownership of it. | 214 // take an ownership of it. |
| 359 void SetShelfItemDelegateManagerForTest( | 215 void SetShelfItemDelegateManagerForTest( |
| 360 ash::ShelfItemDelegateManager* manager); | 216 ash::ShelfItemDelegateManager* manager); |
| 361 | 217 |
| 362 private: | 218 private: |
| 363 friend class ChromeLauncherControllerTest; | 219 friend class ChromeLauncherControllerImplTest; |
| 364 friend class ShelfAppBrowserTest; | 220 friend class ShelfAppBrowserTest; |
| 365 friend class LauncherPlatformAppBrowserTest; | 221 friend class LauncherPlatformAppBrowserTest; |
| 366 | 222 |
| 367 typedef std::map<ash::ShelfID, LauncherItemController*> IDToItemControllerMap; | 223 typedef std::map<ash::ShelfID, LauncherItemController*> IDToItemControllerMap; |
| 368 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; | 224 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; |
| 369 | 225 |
| 370 // Remembers / restores list of running applications. | 226 // Remembers / restores list of running applications. |
| 371 // Note that this order will neither be stored in the preference nor will it | 227 // Note that this order will neither be stored in the preference nor will it |
| 372 // remember the order of closed applications since it is only temporary. | 228 // remember the order of closed applications since it is only temporary. |
| 373 void RememberUnpinnedRunningApplicationOrder(); | 229 void RememberUnpinnedRunningApplicationOrder(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 | 270 |
| 415 // Returns the shelf item status for the given |app_id|, which can be either | 271 // Returns the shelf item status for the given |app_id|, which can be either |
| 416 // STATUS_ACTIVE (if the app is active), STATUS_RUNNING (if there is such an | 272 // STATUS_ACTIVE (if the app is active), STATUS_RUNNING (if there is such an |
| 417 // app) or STATUS_CLOSED. | 273 // app) or STATUS_CLOSED. |
| 418 ash::ShelfItemStatus GetAppState(const std::string& app_id); | 274 ash::ShelfItemStatus GetAppState(const std::string& app_id); |
| 419 | 275 |
| 420 // Creates an app launcher to insert at |index|. Note that |index| may be | 276 // Creates an app launcher to insert at |index|. Note that |index| may be |
| 421 // adjusted by the model to meet ordering constraints. | 277 // adjusted by the model to meet ordering constraints. |
| 422 // The |shelf_item_type| will be set into the ShelfModel. | 278 // The |shelf_item_type| will be set into the ShelfModel. |
| 423 ash::ShelfID InsertAppLauncherItem(LauncherItemController* controller, | 279 ash::ShelfID InsertAppLauncherItem(LauncherItemController* controller, |
| 424 const std::string& app_id, | 280 const std::string& app_id, |
| 425 ash::ShelfItemStatus status, | 281 ash::ShelfItemStatus status, |
| 426 int index, | 282 int index, |
| 427 ash::ShelfItemType shelf_item_type); | 283 ash::ShelfItemType shelf_item_type); |
| 428 | 284 |
| 429 // Enumerate all Web contents which match a given shortcut |controller|. | 285 // Enumerate all Web contents which match a given shortcut |controller|. |
| 430 std::vector<content::WebContents*> GetV1ApplicationsFromController( | 286 std::vector<content::WebContents*> GetV1ApplicationsFromController( |
| 431 LauncherItemController* controller); | 287 LauncherItemController* controller); |
| 432 | 288 |
| 433 // Create ShelfItem for Browser Shortcut. | 289 // Create ShelfItem for Browser Shortcut. |
| 434 ash::ShelfID CreateBrowserShortcutLauncherItem(); | 290 ash::ShelfID CreateBrowserShortcutLauncherItem(); |
| 435 | 291 |
| 436 // Check if the given |web_contents| is in incognito mode. | 292 // Check if the given |web_contents| is in incognito mode. |
| 437 bool IsIncognito(const content::WebContents* web_contents) const; | 293 bool IsIncognito(const content::WebContents* web_contents) const; |
| 438 | 294 |
| 439 // Update browser shortcut's index. | 295 // Update browser shortcut's index. |
| 440 void PersistChromeItemIndex(int index); | 296 void PersistChromeItemIndex(int index); |
| 441 | 297 |
| 442 // Depending on the provided flags, move either the chrome icon, the app icon | 298 // Depending on the provided flags, move either the chrome icon, the app icon |
| 443 // or none to the given |target_index|. The provided |chrome_index| and | 299 // or none to the given |target_index|. The provided |chrome_index| and |
| 444 // |app_list_index| locations will get adjusted within this call to finalize | 300 // |app_list_index| locations will get adjusted within this call to finalize |
| 445 // the action and to make sure that the other item can still be moved | 301 // the action and to make sure that the other item can still be moved |
| 446 // afterwards (index adjustments). | 302 // afterwards (index adjustments). |
| 447 void MoveChromeOrApplistToFinalPosition( | 303 void MoveChromeOrApplistToFinalPosition(bool is_chrome, |
| 448 bool is_chrome, | 304 bool is_app_list, |
| 449 bool is_app_list, | 305 int target_index, |
| 450 int target_index, | 306 int* chrome_index, |
| 451 int* chrome_index, | 307 int* app_list_index); |
| 452 int* app_list_index); | |
| 453 | 308 |
| 454 // Finds the index of where to insert the next item. | 309 // Finds the index of where to insert the next item. |
| 455 int FindInsertionPoint(bool is_app_list); | 310 int FindInsertionPoint(bool is_app_list); |
| 456 | 311 |
| 457 // Get the browser shortcut's index in the shelf using the current's systems | 312 // Get the browser shortcut's index in the shelf using the current's systems |
| 458 // configuration of pinned and known (but not running) apps. | 313 // configuration of pinned and known (but not running) apps. |
| 459 int GetChromeIconIndexForCreation(); | 314 int GetChromeIconIndexForCreation(); |
| 460 | 315 |
| 461 // Close all windowed V1 applications of a certain extension which was already | 316 // Close all windowed V1 applications of a certain extension which was already |
| 462 // deleted. | 317 // deleted. |
| 463 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, | 318 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id, |
| 464 const Profile* profile); | 319 const Profile* profile); |
| 465 | 320 |
| 466 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. | 321 // Set ShelfItemDelegate |item_delegate| for |id| and take an ownership. |
| 467 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. | 322 // TODO(simon.hong81): Make this take a scoped_ptr of |item_delegate|. |
| 468 void SetShelfItemDelegate(ash::ShelfID id, | 323 void SetShelfItemDelegate(ash::ShelfID id, |
| 469 ash::ShelfItemDelegate* item_delegate); | 324 ash::ShelfItemDelegate* item_delegate); |
| 470 | 325 |
| 471 // Attach to a specific profile. | 326 // Attach to a specific profile. |
| 472 void AttachProfile(Profile* proifile); | 327 void AttachProfile(Profile* proifile); |
| 473 | 328 |
| 474 // Forget the current profile to allow attaching to a new one. | 329 // Forget the current profile to allow attaching to a new one. |
| 475 void ReleaseProfile(); | 330 void ReleaseProfile(); |
| 476 | 331 |
| 477 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); | 332 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); |
| 478 | 333 |
| 479 static ChromeLauncherController* instance_; | |
| 480 | |
| 481 ash::ShelfModel* model_; | 334 ash::ShelfModel* model_; |
| 482 | 335 |
| 483 ash::ShelfItemDelegateManager* item_delegate_manager_; | 336 ash::ShelfItemDelegateManager* item_delegate_manager_; |
| 484 | 337 |
| 485 // Profile used for prefs and loading extensions. This is NOT necessarily the | 338 // Profile used for prefs and loading extensions. This is NOT necessarily the |
| 486 // profile new windows are created with. | 339 // profile new windows are created with. |
| 487 Profile* profile_; | 340 Profile* profile_; |
| 488 | 341 |
| 489 // Controller items in this map are owned by |ShelfItemDelegateManager|. | 342 // Controller items in this map are owned by |ShelfItemDelegateManager|. |
| 490 IDToItemControllerMap id_to_item_controller_map_; | 343 IDToItemControllerMap id_to_item_controller_map_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 375 |
| 523 // If true, incoming pinned state changes should be ignored. | 376 // If true, incoming pinned state changes should be ignored. |
| 524 bool ignore_persist_pinned_state_change_; | 377 bool ignore_persist_pinned_state_change_; |
| 525 | 378 |
| 526 // The list of running & un-pinned applications for different users on hidden | 379 // The list of running & un-pinned applications for different users on hidden |
| 527 // desktops. | 380 // desktops. |
| 528 typedef std::vector<std::string> RunningAppListIds; | 381 typedef std::vector<std::string> RunningAppListIds; |
| 529 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; | 382 typedef std::map<std::string, RunningAppListIds> RunningAppListIdMap; |
| 530 RunningAppListIdMap last_used_running_application_order_; | 383 RunningAppListIdMap last_used_running_application_order_; |
| 531 | 384 |
| 532 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); | 385 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerImpl); |
| 533 }; | 386 }; |
| 534 | 387 |
| 535 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 388 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_IMPL_H_ |
| OLD | NEW |