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