| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_CHROME_LAUNCHER_DELEGATE_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_CHROME_LAUNCHER_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_CHROME_LAUNCHER_DELEGATE_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_CHROME_LAUNCHER_DELEGATE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "ash/launcher/launcher_delegate.h" | 13 #include "ash/launcher/launcher_delegate.h" |
| 14 #include "ash/launcher/launcher_model_observer.h" | 14 #include "ash/launcher/launcher_model_observer.h" |
| 15 #include "ash/launcher/launcher_types.h" | 15 #include "ash/launcher/launcher_types.h" |
| 16 #include "ash/wm/shelf_auto_hide_behavior.h" | 16 #include "ash/wm/shelf_auto_hide_behavior.h" |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "chrome/browser/extensions/extension_prefs.h" |
| 20 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 21 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 22 | 23 |
| 23 namespace ash { | 24 namespace ash { |
| 24 class LauncherModel; | 25 class LauncherModel; |
| 25 } | 26 } |
| 26 | 27 |
| 27 class LauncherUpdater; | 28 class LauncherUpdater; |
| 28 class LauncherUpdaterTest; | 29 class LauncherUpdaterTest; |
| 29 class PrefService; | 30 class PrefService; |
| 30 class Profile; | 31 class Profile; |
| 31 class TabContentsWrapper; | 32 class TabContentsWrapper; |
| 32 | 33 |
| 33 // ChromeLauncherDelegate manages the launcher items needed for tabbed browsers | 34 // ChromeLauncherDelegate manages the launcher items needed for tabbed browsers |
| 34 // and apps. It does this by way of LauncherUpdaters. | 35 // and apps. It does this by way of LauncherUpdaters. |
| 35 // TODO: rename this. ChromeLauncherDelegate is a poor name for what it actually | 36 // TODO: rename this. ChromeLauncherDelegate is a poor name for what it actually |
| 36 // does. | 37 // does. |
| 37 class ChromeLauncherDelegate : public ash::LauncherDelegate, | 38 class ChromeLauncherDelegate : public ash::LauncherDelegate, |
| 38 public ash::LauncherModelObserver, | 39 public ash::LauncherModelObserver, |
| 39 public content::NotificationObserver { | 40 public content::NotificationObserver { |
| 40 public: | 41 public: |
| 41 // Indicates what should happen when the app is launched. | |
| 42 enum AppType { | |
| 43 APP_TYPE_WINDOW, | |
| 44 APP_TYPE_APP_PANEL, // Panel opened from the app list. | |
| 45 APP_TYPE_EXTENSION_PANEL, // Panel opened by an extension. | |
| 46 APP_TYPE_TAB | |
| 47 }; | |
| 48 | |
| 49 // Indicates if a launcher item is incognito or not. | 42 // Indicates if a launcher item is incognito or not. |
| 50 enum IncognitoState { | 43 enum IncognitoState { |
| 51 STATE_INCOGNITO, | 44 STATE_INCOGNITO, |
| 52 STATE_NOT_INCOGNITO, | 45 STATE_NOT_INCOGNITO, |
| 53 }; | 46 }; |
| 54 | 47 |
| 55 // Interface used to load app icons. This is in it's own class so that it can | 48 // Interface used to load app icons. This is in it's own class so that it can |
| 56 // be mocked. | 49 // be mocked. |
| 57 class AppIconLoader { | 50 class AppIconLoader { |
| 58 public: | 51 public: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 85 | 78 |
| 86 // Creates a new tabbed item on the launcher for |updater|. | 79 // Creates a new tabbed item on the launcher for |updater|. |
| 87 ash::LauncherID CreateTabbedLauncherItem(LauncherUpdater* updater, | 80 ash::LauncherID CreateTabbedLauncherItem(LauncherUpdater* updater, |
| 88 IncognitoState is_incognito, | 81 IncognitoState is_incognito, |
| 89 ash::LauncherItemStatus status); | 82 ash::LauncherItemStatus status); |
| 90 | 83 |
| 91 // Creates a new app item on the launcher for |updater|. If there is an | 84 // Creates a new app item on the launcher for |updater|. If there is an |
| 92 // existing pinned app that isn't running on the launcher, its id is returned. | 85 // existing pinned app that isn't running on the launcher, its id is returned. |
| 93 ash::LauncherID CreateAppLauncherItem(LauncherUpdater* updater, | 86 ash::LauncherID CreateAppLauncherItem(LauncherUpdater* updater, |
| 94 const std::string& app_id, | 87 const std::string& app_id, |
| 95 AppType app_type, | |
| 96 ash::LauncherItemStatus status); | 88 ash::LauncherItemStatus status); |
| 97 | 89 |
| 98 // Updates the running status of an item. | 90 // Updates the running status of an item. |
| 99 void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); | 91 void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); |
| 100 | 92 |
| 101 // Invoked when the underlying browser/app is closed. | 93 // Invoked when the underlying browser/app is closed. |
| 102 void LauncherItemClosed(ash::LauncherID id); | 94 void LauncherItemClosed(ash::LauncherID id); |
| 103 | 95 |
| 104 // Unpins the specified id, closing if not running. | 96 // Unpins the specified id, closing if not running. |
| 105 void Unpin(ash::LauncherID id); | 97 void Unpin(ash::LauncherID id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 116 | 108 |
| 117 // Opens the specified item. | 109 // Opens the specified item. |
| 118 void Open(ash::LauncherID id); | 110 void Open(ash::LauncherID id); |
| 119 | 111 |
| 120 // Closes the specified item. | 112 // Closes the specified item. |
| 121 void Close(ash::LauncherID id); | 113 void Close(ash::LauncherID id); |
| 122 | 114 |
| 123 // Returns true if the specified item is open. | 115 // Returns true if the specified item is open. |
| 124 bool IsOpen(ash::LauncherID id); | 116 bool IsOpen(ash::LauncherID id); |
| 125 | 117 |
| 126 // Returns the type of app for the specified id. | 118 // Returns the launch type of app for the specified id. |
| 127 AppType GetAppType(ash::LauncherID id); | 119 ExtensionPrefs::LaunchType GetLaunchType(ash::LauncherID id); |
| 128 | 120 |
| 129 // Returns the id of the app for the specified tab. | 121 // Returns the id of the app for the specified tab. |
| 130 std::string GetAppID(TabContentsWrapper* tab); | 122 std::string GetAppID(TabContentsWrapper* tab); |
| 131 | 123 |
| 132 // Sets the image for an app tab. This is intended to be invoked from the | 124 // Sets the image for an app tab. This is intended to be invoked from the |
| 133 // AppIconLoader. | 125 // AppIconLoader. |
| 134 void SetAppImage(const std::string& app_id, const SkBitmap* image); | 126 void SetAppImage(const std::string& app_id, const SkBitmap* image); |
| 135 | 127 |
| 136 // Returns true if a pinned launcher item with given |app_id| could be found. | 128 // Returns true if a pinned launcher item with given |app_id| could be found. |
| 137 bool IsAppPinned(const std::string& app_id); | 129 bool IsAppPinned(const std::string& app_id); |
| 138 | 130 |
| 139 // Pins an app with |app_id| to launcher. If there is a running instance in | 131 // Pins an app with |app_id| to launcher. If there is a running instance in |
| 140 // launcher, the running instance is pinned. If there is no running instance, | 132 // launcher, the running instance is pinned. If there is no running instance, |
| 141 // a new launcher item is created with |app_type| and pinned. | 133 // a new launcher item is created and pinned. |
| 142 void PinAppWithID(const std::string& app_id, AppType app_type); | 134 void PinAppWithID(const std::string& app_id); |
| 143 | 135 |
| 144 // Modifies an app shortcut to open with the new |app_type|. | 136 // Updates the launche type of the app for the specified id to |launch_type|. |
| 145 void SetAppType(ash::LauncherID id, AppType app_type); | 137 void SetLaunchType(ash::LauncherID id, |
| 138 ExtensionPrefs::LaunchType launch_type); |
| 146 | 139 |
| 147 // Unpins any app items whose id is |app_id|. | 140 // Unpins any app items whose id is |app_id|. |
| 148 void UnpinAppsWithID(const std::string& app_id); | 141 void UnpinAppsWithID(const std::string& app_id); |
| 149 | 142 |
| 150 ash::LauncherModel* model() { return model_; } | 143 ash::LauncherModel* model() { return model_; } |
| 151 | 144 |
| 152 Profile* profile() { return profile_; } | 145 Profile* profile() { return profile_; } |
| 153 | 146 |
| 154 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior behavior); | 147 void SetAutoHideBehavior(ash::ShelfAutoHideBehavior behavior); |
| 155 | 148 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // Used to identity an item on the launcher. | 180 // Used to identity an item on the launcher. |
| 188 struct Item { | 181 struct Item { |
| 189 Item(); | 182 Item(); |
| 190 ~Item(); | 183 ~Item(); |
| 191 | 184 |
| 192 bool is_pinned() const { return updater == NULL; } | 185 bool is_pinned() const { return updater == NULL; } |
| 193 | 186 |
| 194 // Type of item. | 187 // Type of item. |
| 195 ItemType item_type; | 188 ItemType item_type; |
| 196 | 189 |
| 197 // If |item_type| is |TYPE_APP|, this identifies how the app is launched. | |
| 198 AppType app_type; | |
| 199 | |
| 200 // ID of the app. | 190 // ID of the app. |
| 201 std::string app_id; | 191 std::string app_id; |
| 202 | 192 |
| 203 // The LauncherUpdater this item came from. NULL if a shortcut. | 193 // The LauncherUpdater this item came from. NULL if a shortcut. |
| 204 LauncherUpdater* updater; | 194 LauncherUpdater* updater; |
| 205 }; | 195 }; |
| 206 | 196 |
| 207 typedef std::map<ash::LauncherID, Item> IDToItemMap; | 197 typedef std::map<ash::LauncherID, Item> IDToItemMap; |
| 208 | 198 |
| 209 // Updates the pinned pref state. The pinned state consists of a list pref. | 199 // Updates the pinned pref state. The pinned state consists of a list pref. |
| 210 // Each item of the list is a dictionary. The key |kAppIDPath| gives the | 200 // Each item of the list is a dictionary. The key |kAppIDPath| gives the |
| 211 // id of the app. |kAppTypePath| is one of |kAppTypeTab| or |kAppTypeWindow| | 201 // id of the app. |
| 212 // and indicates how the app is opened. | |
| 213 void PersistPinnedState(); | 202 void PersistPinnedState(); |
| 214 | 203 |
| 215 // Sets the AppIconLoader, taking ownership of |loader|. This is intended for | 204 // Sets the AppIconLoader, taking ownership of |loader|. This is intended for |
| 216 // testing. | 205 // testing. |
| 217 void SetAppIconLoaderForTest(AppIconLoader* loader); | 206 void SetAppIconLoaderForTest(AppIconLoader* loader); |
| 218 | 207 |
| 219 // Returns the profile used for new windows. | 208 // Returns the profile used for new windows. |
| 220 Profile* GetProfileForNewWindows(); | 209 Profile* GetProfileForNewWindows(); |
| 221 | 210 |
| 222 // Checks |pending_pinnned_apps_| list and creates pinned app items for apps | 211 // Checks |pending_pinnned_apps_| list and creates pinned app items for apps |
| (...skipping 19 matching lines...) Expand all Loading... |
| 242 // are installed (via sync or external extension provider.) The order of the | 231 // are installed (via sync or external extension provider.) The order of the |
| 243 // list reflects the original order in pinned app list. | 232 // list reflects the original order in pinned app list. |
| 244 std::queue<Item> pending_pinned_apps_; | 233 std::queue<Item> pending_pinned_apps_; |
| 245 | 234 |
| 246 content::NotificationRegistrar registrar_; | 235 content::NotificationRegistrar registrar_; |
| 247 | 236 |
| 248 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherDelegate); | 237 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherDelegate); |
| 249 }; | 238 }; |
| 250 | 239 |
| 251 #endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_CHROME_LAUNCHER_DELEGATE_H_ | 240 #endif // CHROME_BROWSER_UI_VIEWS_ASH_LAUNCHER_CHROME_LAUNCHER_DELEGATE_H_ |
| OLD | NEW |