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