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_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 <set> |
8 #include <string> | 11 #include <string> |
| 12 #include <vector> |
9 | 13 |
| 14 #include "ash/display/display_controller.h" |
10 #include "ash/launcher/launcher_delegate.h" | 15 #include "ash/launcher/launcher_delegate.h" |
| 16 #include "ash/launcher/launcher_model_observer.h" |
11 #include "ash/launcher/launcher_types.h" | 17 #include "ash/launcher/launcher_types.h" |
| 18 #include "ash/shelf/shelf_layout_manager_observer.h" |
12 #include "ash/shelf/shelf_types.h" | 19 #include "ash/shelf/shelf_types.h" |
| 20 #include "ash/shell_observer.h" |
| 21 #include "base/basictypes.h" |
| 22 #include "base/compiler_specific.h" |
| 23 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 24 #include "base/memory/scoped_vector.h" |
| 25 #include "base/prefs/pref_change_registrar.h" |
14 #include "chrome/browser/extensions/app_icon_loader.h" | 26 #include "chrome/browser/extensions/app_icon_loader.h" |
15 #include "chrome/browser/extensions/extension_prefs.h" | 27 #include "chrome/browser/extensions/extension_prefs.h" |
| 28 #include "chrome/browser/prefs/pref_service_syncable_observer.h" |
| 29 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
| 30 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 31 #include "chrome/browser/ui/browser_list_observer.h" |
| 32 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" |
| 33 #include "content/public/browser/notification_observer.h" |
| 34 #include "ui/aura/window_observer.h" |
16 | 35 |
17 class LauncherItemControllerPerAppTest; | 36 class AppSyncUIState; |
| 37 class Browser; |
| 38 class BrowserShortcutLauncherItemController; |
| 39 class ExtensionEnableFlow; |
| 40 class GURL; |
18 class LauncherItemController; | 41 class LauncherItemController; |
19 class Profile; | 42 class Profile; |
20 class ChromeLauncherAppMenuItem; | 43 class ShellWindowLauncherController; |
21 class ChromeLauncherControllerPerApp; | 44 class TabContents; |
22 | 45 |
23 namespace ash { | 46 namespace ash { |
24 class LauncherModel; | 47 class LauncherModel; |
25 } | 48 } |
26 | 49 |
27 namespace aura { | 50 namespace aura { |
28 class Window; | 51 class Window; |
29 class RootWindow; | |
30 } | 52 } |
31 | 53 |
32 namespace content { | 54 namespace content { |
| 55 class NotificationRegistrar; |
33 class WebContents; | 56 class WebContents; |
34 } | 57 } |
35 | 58 |
36 namespace ui { | 59 namespace ui { |
37 class BaseWindow; | 60 class BaseWindow; |
38 } | 61 } |
39 | 62 |
40 // A list of the elements which makes up a simple menu description. | 63 // A list of the elements which makes up a simple menu description. |
41 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; | 64 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; |
42 | 65 |
43 // ChromeLauncherController manages the launcher items needed for content | 66 // ChromeLauncherController manages the launcher items needed for content |
44 // windows. Launcher items have a type, an optional app id, and a controller. | 67 // windows. Launcher items have a type, an optional app id, and a controller. |
45 // ChromeLauncherController will furthermore create the particular | 68 // This incarnation groups running tabs/windows in application specific lists. |
46 // implementation of interest - either sorting by application (new) or sorting | 69 // * Browser app windows have BrowserLauncherItemController, owned by the |
47 // by browser (old). | 70 // BrowserView instance. |
48 // * Tabbed browsers and browser app windows have BrowserLauncherItemController, | |
49 // owned by the BrowserView instance. | |
50 // * App shell windows have ShellWindowLauncherItemController, owned by | 71 // * App shell windows have ShellWindowLauncherItemController, owned by |
51 // ShellWindowLauncherController. | 72 // ShellWindowLauncherController. |
52 // * Shortcuts have no LauncherItemController. | 73 // * Shortcuts have no LauncherItemController. |
53 class ChromeLauncherController | 74 class ChromeLauncherController : public ash::LauncherDelegate, |
54 : public ash::LauncherDelegate, | 75 public ash::LauncherModelObserver, |
55 public extensions::AppIconLoader::Delegate { | 76 public ash::ShellObserver, |
| 77 public ash::DisplayController::Observer, |
| 78 public content::NotificationObserver, |
| 79 public extensions::AppIconLoader::Delegate, |
| 80 public PrefServiceSyncableObserver, |
| 81 public AppSyncUIStateObserver, |
| 82 public ExtensionEnableFlowDelegate, |
| 83 public chrome::BrowserListObserver, |
| 84 public ash::ShelfLayoutManagerObserver { |
56 public: | 85 public: |
57 // Indicates if a launcher item is incognito or not. | 86 // Indicates if a launcher item is incognito or not. |
58 enum IncognitoState { | 87 enum IncognitoState { |
59 STATE_INCOGNITO, | 88 STATE_INCOGNITO, |
60 STATE_NOT_INCOGNITO, | 89 STATE_NOT_INCOGNITO, |
61 }; | 90 }; |
62 | 91 |
63 // Used to update the state of non plaform apps, as web contents change. | 92 // Used to update the state of non plaform apps, as web contents change. |
64 enum AppState { | 93 enum AppState { |
65 APP_STATE_ACTIVE, | 94 APP_STATE_ACTIVE, |
66 APP_STATE_WINDOW_ACTIVE, | 95 APP_STATE_WINDOW_ACTIVE, |
67 APP_STATE_INACTIVE, | 96 APP_STATE_INACTIVE, |
68 APP_STATE_REMOVED | 97 APP_STATE_REMOVED |
69 }; | 98 }; |
70 | 99 |
71 // Mockable interface to get app ids from tabs. | 100 // Mockable interface to get app ids from tabs. |
72 class AppTabHelper { | 101 class AppTabHelper { |
73 public: | 102 public: |
74 virtual ~AppTabHelper() {} | 103 virtual ~AppTabHelper() {} |
75 | 104 |
76 // Returns the app id of the specified tab, or an empty string if there is | 105 // Returns the app id of the specified tab, or an empty string if there is |
77 // no app. | 106 // no app. |
78 virtual std::string GetAppID(content::WebContents* tab) = 0; | 107 virtual std::string GetAppID(content::WebContents* tab) = 0; |
79 | 108 |
80 // Returns true if |id| is valid. Used during restore to ignore no longer | 109 // Returns true if |id| is valid. Used during restore to ignore no longer |
81 // valid extensions. | 110 // valid extensions. |
82 virtual bool IsValidID(const std::string& id) = 0; | 111 virtual bool IsValidID(const std::string& id) = 0; |
83 }; | 112 }; |
84 | 113 |
85 ChromeLauncherController() {} | 114 ChromeLauncherController(Profile* profile, ash::LauncherModel* model); |
86 virtual ~ChromeLauncherController(); | 115 virtual ~ChromeLauncherController(); |
87 | 116 |
88 // Initializes this ChromeLauncherController. | 117 // Initializes this ChromeLauncherController. |
89 virtual void Init() = 0; | 118 void Init(); |
90 | |
91 // Returns the new per application interface of the given launcher. If it is | |
92 // a per browser (old) controller, it will return NULL; | |
93 // TODO(skuhne): Remove when we rip out the old launcher. | |
94 virtual ChromeLauncherControllerPerApp* GetPerAppInterface() = 0; | |
95 | 119 |
96 // Creates an instance. | 120 // Creates an instance. |
97 static ChromeLauncherController* CreateInstance(Profile* profile, | 121 static ChromeLauncherController* CreateInstance(Profile* profile, |
98 ash::LauncherModel* model); | 122 ash::LauncherModel* model); |
99 | 123 |
100 // Returns the single ChromeLauncherController instance. | 124 // Returns the single ChromeLauncherController instance. |
101 static ChromeLauncherController* instance() { return instance_; } | 125 static ChromeLauncherController* instance() { return instance_; } |
102 | 126 |
103 // Creates a new tabbed item on the launcher for |controller|. | |
104 virtual ash::LauncherID CreateTabbedLauncherItem( | |
105 LauncherItemController* controller, | |
106 IncognitoState is_incognito, | |
107 ash::LauncherItemStatus status) = 0; | |
108 | |
109 // Creates a new app item on the launcher for |controller|. | 127 // Creates a new app item on the launcher for |controller|. |
110 virtual ash::LauncherID CreateAppLauncherItem( | 128 ash::LauncherID CreateAppLauncherItem(LauncherItemController* controller, |
111 LauncherItemController* controller, | 129 const std::string& app_id, |
112 const std::string& app_id, | 130 ash::LauncherItemStatus status); |
113 ash::LauncherItemStatus status) = 0; | 131 |
114 | 132 // Updates the running status of an item. It will also update the status of |
115 // Updates the running status of an item. | 133 // browsers launcher item if needed. |
116 virtual void SetItemStatus(ash::LauncherID id, | 134 void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); |
117 ash::LauncherItemStatus status) = 0; | |
118 | 135 |
119 // Updates the controller associated with id (which should be a shortcut). | 136 // Updates the controller associated with id (which should be a shortcut). |
120 // |controller| remains owned by caller. | 137 // |controller| remains owned by caller. |
121 virtual void SetItemController(ash::LauncherID id, | 138 void SetItemController(ash::LauncherID id, |
122 LauncherItemController* controller) = 0; | 139 LauncherItemController* controller); |
123 | 140 |
124 // Closes or unpins the launcher item. | 141 // Closes or unpins the launcher item. |
125 virtual void CloseLauncherItem(ash::LauncherID id) = 0; | 142 void CloseLauncherItem(ash::LauncherID id); |
126 | 143 |
127 // Pins the specified id. Currently only supports platform apps. | 144 // Pins the specified id. Currently only supports platform apps. |
128 virtual void Pin(ash::LauncherID id) = 0; | 145 void Pin(ash::LauncherID id); |
129 | 146 |
130 // Unpins the specified id, closing if not running. | 147 // Unpins the specified id, closing if not running. |
131 virtual void Unpin(ash::LauncherID id) = 0; | 148 void Unpin(ash::LauncherID id); |
132 | 149 |
133 // Returns true if the item identified by |id| is pinned. | 150 // Returns true if the item identified by |id| is pinned. |
134 virtual bool IsPinned(ash::LauncherID id) = 0; | 151 bool IsPinned(ash::LauncherID id); |
135 | 152 |
136 // Pins/unpins the specified id. | 153 // Pins/unpins the specified id. |
137 virtual void TogglePinned(ash::LauncherID id) = 0; | 154 void TogglePinned(ash::LauncherID id); |
138 | 155 |
139 // Returns true if the specified item can be pinned or unpinned. Only apps can | 156 // Returns true if the specified item can be pinned or unpinned. Only apps can |
140 // be pinned. | 157 // be pinned. |
141 virtual bool IsPinnable(ash::LauncherID id) const = 0; | 158 bool IsPinnable(ash::LauncherID id) const; |
142 | 159 |
143 // If there is no launcher item in the launcher for application |app_id|, one | 160 // If there is no launcher item in the launcher for application |app_id|, one |
144 // gets created. The (existing or created) launcher items get then locked | 161 // gets created. The (existing or created) launcher items get then locked |
145 // against a users un-pinning removal. | 162 // against a users un-pinning removal. |
146 virtual void LockV1AppWithID(const std::string& app_id) = 0; | 163 void LockV1AppWithID(const std::string& app_id); |
147 | 164 |
148 // A previously locked launcher item of type |app_id| gets unlocked. If the | 165 // A previously locked launcher item of type |app_id| gets unlocked. If the |
149 // lock count reaches 0 and the item is not pinned it will go away. | 166 // lock count reaches 0 and the item is not pinned it will go away. |
150 virtual void UnlockV1AppWithID(const std::string& app_id) = 0; | 167 void UnlockV1AppWithID(const std::string& app_id); |
151 | 168 |
152 // Requests that the launcher item controller specified by |id| open a new | 169 // Requests that the launcher item controller specified by |id| open a new |
153 // instance of the app. |event_flags| holds the flags of the event which | 170 // instance of the app. |event_flags| holds the flags of the event which |
154 // triggered this command. | 171 // triggered this command. |
155 virtual void Launch(ash::LauncherID id, int event_flags) = 0; | 172 void Launch(ash::LauncherID id, int event_flags); |
156 | 173 |
157 // Closes the specified item. | 174 // Closes the specified item. |
158 virtual void Close(ash::LauncherID id) = 0; | 175 void Close(ash::LauncherID id); |
159 | 176 |
160 // Returns true if the specified item is open. | 177 // Returns true if the specified item is open. |
161 virtual bool IsOpen(ash::LauncherID id) = 0; | 178 bool IsOpen(ash::LauncherID id); |
162 | 179 |
163 // Returns true if the specified item is for a platform app. | 180 // Returns true if the specified item is for a platform app. |
164 virtual bool IsPlatformApp(ash::LauncherID id) = 0; | 181 bool IsPlatformApp(ash::LauncherID id); |
165 | 182 |
166 // Opens a new instance of the application identified by |app_id|. | 183 // Opens a new instance of the application identified by |app_id|. |
167 // Used by the app-list, and by pinned-app launcher items. | 184 // Used by the app-list, and by pinned-app launcher items. |
168 virtual void LaunchApp(const std::string& app_id, int event_flags) = 0; | 185 void LaunchApp(const std::string& app_id, int event_flags); |
169 | 186 |
170 // If |app_id| is running, reactivates the app's most recently active window, | 187 // If |app_id| is running, reactivates the app's most recently active window, |
171 // otherwise launches and activates the app. | 188 // otherwise launches and activates the app. |
172 // Used by the app-list, and by pinned-app launcher items. | 189 // Used by the app-list, and by pinned-app launcher items. |
173 virtual void ActivateApp(const std::string& app_id, int event_flags) = 0; | 190 void ActivateApp(const std::string& app_id, int event_flags); |
174 | 191 |
175 // Returns the launch type of app for the specified id. | 192 // Returns the launch type of app for the specified id. |
176 virtual extensions::ExtensionPrefs::LaunchType GetLaunchType( | 193 extensions::ExtensionPrefs::LaunchType GetLaunchType(ash::LauncherID id); |
177 ash::LauncherID id) = 0; | |
178 | 194 |
179 // Returns the id of the app for the specified tab. | 195 // Returns the id of the app for the specified tab. |
180 virtual std::string GetAppID(content::WebContents* tab) = 0; | 196 std::string GetAppID(content::WebContents* tab); |
181 | 197 |
182 // Returns the launcherID of the first non-panel item whose app_id | 198 std::string GetAppIDForLauncherID(ash::LauncherID id); |
183 // matches |app_id| or 0 if none match. | |
184 virtual ash::LauncherID GetLauncherIDForAppID(const std::string& app_id) = 0; | |
185 | |
186 // Returns the id of the app for the specified id (which must exist). | |
187 virtual std::string GetAppIDForLauncherID(ash::LauncherID id) = 0; | |
188 | 199 |
189 // Set the image for a specific launcher item (e.g. when set by the app). | 200 // Set the image for a specific launcher item (e.g. when set by the app). |
190 virtual void SetLauncherItemImage(ash::LauncherID launcher_id, | 201 void SetLauncherItemImage(ash::LauncherID launcher_id, |
191 const gfx::ImageSkia& image) = 0; | 202 const gfx::ImageSkia& image); |
192 | 203 |
193 // Returns true if a pinned launcher item with given |app_id| could be found. | 204 // Find out if the given application |id| is a windowed app item and not a |
194 virtual bool IsAppPinned(const std::string& app_id) = 0; | 205 // pinned item in the launcher. |
195 | 206 bool IsWindowedAppInLauncher(const std::string& app_id); |
196 // Pins an app with |app_id| to launcher. If there is a running instance in | |
197 // launcher, the running instance is pinned. If there is no running instance, | |
198 // a new launcher item is created and pinned. | |
199 virtual void PinAppWithID(const std::string& app_id) = 0; | |
200 | 207 |
201 // Updates the launche type of the app for the specified id to |launch_type|. | 208 // Updates the launche type of the app for the specified id to |launch_type|. |
202 virtual void SetLaunchType( | 209 void SetLaunchType(ash::LauncherID id, |
203 ash::LauncherID id, | 210 extensions::ExtensionPrefs::LaunchType launch_type); |
204 extensions::ExtensionPrefs::LaunchType launch_type) = 0; | |
205 | |
206 // Unpins any app items whose id is |app_id|. | |
207 virtual void UnpinAppsWithID(const std::string& app_id) = 0; | |
208 | 211 |
209 // Returns true if the user is currently logged in as a guest. | 212 // Returns true if the user is currently logged in as a guest. |
210 virtual bool IsLoggedInAsGuest() = 0; | 213 // Makes virtual for unittest in LauncherContextMenuTest. |
| 214 virtual bool IsLoggedInAsGuest(); |
211 | 215 |
212 // Invoked when user clicks on button in the launcher and there is no last | 216 // Invoked when user clicks on button in the launcher and there is no last |
213 // used window (or CTRL is held with the click). | 217 // used window (or CTRL is held with the click). |
214 virtual void CreateNewWindow() = 0; | 218 void CreateNewWindow(); |
215 | 219 |
216 // Invoked when the user clicks on button in the launcher to create a new | 220 // Invoked when the user clicks on button in the launcher to create a new |
217 // incognito window. | 221 // incognito window. |
218 virtual void CreateNewIncognitoWindow() = 0; | 222 void CreateNewIncognitoWindow(); |
219 | 223 |
220 // Checks whether the user is allowed to pin apps. Pinning may be disallowed | 224 // Checks whether the user is allowed to pin apps. Pinning may be disallowed |
221 // by policy in case there is a pre-defined set of pinned apps. | 225 // by policy in case there is a pre-defined set of pinned apps. |
222 virtual bool CanPin() const = 0; | 226 bool CanPin() const; |
223 | 227 |
224 // Updates the pinned pref state. The pinned state consists of a list pref. | 228 // Updates the pinned pref state. The pinned state consists of a list pref. |
225 // Each item of the list is a dictionary. The key |kAppIDPath| gives the | 229 // Each item of the list is a dictionary. The key |kAppIDPath| gives the |
226 // id of the app. | 230 // id of the app. |
227 virtual void PersistPinnedState() = 0; | 231 void PersistPinnedState(); |
228 | 232 |
229 virtual ash::LauncherModel* model() = 0; | 233 ash::LauncherModel* model(); |
230 | 234 |
231 virtual Profile* profile() = 0; | 235 Profile* profile(); |
232 | 236 |
233 // Gets the shelf auto-hide behavior on |root_window|. | 237 // Gets the shelf auto-hide behavior on |root_window|. |
234 virtual ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( | 238 ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( |
235 aura::RootWindow* root_window) const = 0; | 239 aura::RootWindow* root_window) const; |
236 | 240 |
237 // Returns |true| if the user is allowed to modify the shelf auto-hide | 241 // Returns |true| if the user is allowed to modify the shelf auto-hide |
238 // behavior on |root_window|. | 242 // behavior on |root_window|. |
239 virtual bool CanUserModifyShelfAutoHideBehavior( | 243 bool CanUserModifyShelfAutoHideBehavior(aura::RootWindow* root_window) const; |
240 aura::RootWindow* root_window) const = 0; | |
241 | 244 |
242 // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the | 245 // Toggles the shelf auto-hide behavior on |root_window|. Does nothing if the |
243 // user is not allowed to modify the auto-hide behavior. | 246 // user is not allowed to modify the auto-hide behavior. |
244 virtual void ToggleShelfAutoHideBehavior(aura::RootWindow* root_window) = 0; | 247 void ToggleShelfAutoHideBehavior(aura::RootWindow* root_window); |
245 | 248 |
246 // The tab no longer represents its previously identified application. | 249 // The tab no longer represents its previously identified application. |
247 virtual void RemoveTabFromRunningApp(content::WebContents* tab, | 250 void RemoveTabFromRunningApp(content::WebContents* tab, |
248 const std::string& app_id) = 0; | 251 const std::string& app_id); |
249 | 252 |
250 // Notify the controller that the state of an non platform app's tabs | 253 // Notify the controller that the state of an non platform app's tabs |
251 // have changed, | 254 // have changed, |
252 virtual void UpdateAppState(content::WebContents* contents, | 255 void UpdateAppState(content::WebContents* contents, AppState app_state); |
253 AppState app_state) = 0; | |
254 | 256 |
255 // Limits application refocusing to urls that match |url| for |id|. | 257 // Limits application refocusing to urls that match |url| for |id|. |
256 virtual void SetRefocusURLPatternForTest(ash::LauncherID id, | 258 void SetRefocusURLPatternForTest(ash::LauncherID id, const GURL& url); |
257 const GURL& url) = 0; | |
258 | 259 |
259 // Returns the extension identified by |app_id|. | 260 // Returns the extension identified by |app_id|. |
260 virtual const extensions::Extension* GetExtensionForAppID( | 261 const extensions::Extension* GetExtensionForAppID( |
261 const std::string& app_id) const = 0; | 262 const std::string& app_id) const; |
262 | 263 |
263 // Activates a |window|. If |allow_minimize| is true and the system allows | 264 // Activates a |window|. If |allow_minimize| is true and the system allows |
264 // it, the the window will get minimized instead. | 265 // it, the the window will get minimized instead. |
265 virtual void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, | 266 void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, |
266 bool allow_minimize) = 0; | 267 bool allow_minimize); |
| 268 |
267 // ash::LauncherDelegate overrides: | 269 // ash::LauncherDelegate overrides: |
268 virtual void ItemSelected(const ash::LauncherItem& item, | 270 virtual void ItemSelected(const ash::LauncherItem& item, |
269 const ui::Event& event) OVERRIDE = 0; | 271 const ui::Event& event) OVERRIDE; |
270 virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE = 0; | 272 virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE; |
271 virtual ui::MenuModel* CreateContextMenu( | 273 virtual ui::MenuModel* CreateContextMenu( |
272 const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE = 0; | 274 const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE; |
273 virtual ash::LauncherMenuModel* CreateApplicationMenu( | 275 virtual ash::LauncherMenuModel* CreateApplicationMenu( |
274 const ash::LauncherItem& item, | 276 const ash::LauncherItem& item, |
275 int event_flags) OVERRIDE = 0; | 277 int event_flags) OVERRIDE; |
276 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE = 0; | 278 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; |
277 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE = 0; | 279 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; |
278 virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE = 0; | 280 virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE; |
279 virtual bool IsPerAppLauncher() OVERRIDE; | 281 virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; |
| 282 virtual void OnLauncherDestroyed(ash::Launcher* launcher) OVERRIDE; |
| 283 virtual ash::LauncherID GetLauncherIDForAppID( |
| 284 const std::string& app_id) OVERRIDE; |
| 285 virtual void PinAppWithID(const std::string& app_id) OVERRIDE; |
| 286 virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; |
| 287 virtual void UnpinAppsWithID(const std::string& app_id) OVERRIDE; |
| 288 |
| 289 // ash::LauncherModelObserver overrides: |
| 290 virtual void LauncherItemAdded(int index) OVERRIDE; |
| 291 virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; |
| 292 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; |
| 293 virtual void LauncherItemChanged(int index, |
| 294 const ash::LauncherItem& old_item) OVERRIDE; |
| 295 virtual void LauncherStatusChanged() OVERRIDE; |
| 296 |
| 297 // content::NotificationObserver overrides: |
| 298 virtual void Observe(int type, |
| 299 const content::NotificationSource& source, |
| 300 const content::NotificationDetails& details) OVERRIDE; |
| 301 |
| 302 // ash::ShellObserver overrides: |
| 303 virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE; |
| 304 |
| 305 // ash::DisplayController::Observer overrides: |
| 306 virtual void OnDisplayConfigurationChanging() OVERRIDE; |
| 307 virtual void OnDisplayConfigurationChanged() OVERRIDE; |
| 308 |
| 309 // PrefServiceSyncableObserver overrides: |
| 310 virtual void OnIsSyncingChanged() OVERRIDE; |
| 311 |
| 312 // AppSyncUIStateObserver overrides: |
| 313 virtual void OnAppSyncUIStatusChanged() OVERRIDE; |
| 314 |
| 315 // ExtensionEnableFlowDelegate overrides: |
| 316 virtual void ExtensionEnableFlowFinished() OVERRIDE; |
| 317 virtual void ExtensionEnableFlowAborted(bool user_initiated) OVERRIDE; |
280 | 318 |
281 // extensions::AppIconLoader overrides: | 319 // extensions::AppIconLoader overrides: |
282 virtual void SetAppImage(const std::string& app_id, | 320 virtual void SetAppImage(const std::string& app_id, |
283 const gfx::ImageSkia& image) OVERRIDE = 0; | 321 const gfx::ImageSkia& image) OVERRIDE; |
| 322 |
| 323 // ash::ShelfLayoutManagerObserver overrides: |
| 324 virtual void OnAutoHideBehaviorChanged( |
| 325 aura::RootWindow* root_window, |
| 326 ash::ShelfAutoHideBehavior new_behavior) OVERRIDE; |
| 327 |
| 328 // Get the list of all running incarnations of this item. |
| 329 // |event_flags| specifies the flags which were set by the event which |
| 330 // triggered this menu generation. It can be used to generate different lists. |
| 331 ChromeLauncherAppMenuItems GetApplicationList(const ash::LauncherItem& item, |
| 332 int event_flags); |
| 333 |
| 334 // Get the list of all tabs which belong to a certain application type. |
| 335 std::vector<content::WebContents*> GetV1ApplicationsFromAppId( |
| 336 std::string app_id); |
| 337 |
| 338 // Activates a specified shell application. |
| 339 void ActivateShellApp(const std::string& app_id, int index); |
| 340 |
| 341 // Checks if a given |web_contents| is known to be associated with an |
| 342 // application of type |app_id|. |
| 343 bool IsWebContentHandledByApplication(content::WebContents* web_contents, |
| 344 const std::string& app_id); |
| 345 |
| 346 // Check if the gMail app is loaded and it can handle the given web content. |
| 347 // This special treatment is required to address crbug.com/234268. |
| 348 bool ContentCanBeHandledByGmailApp(content::WebContents* web_contents); |
| 349 |
| 350 // Get the favicon for the application list entry for |web_contents|. |
| 351 // Note that for incognito windows the incognito icon will be returned. |
| 352 // If |web_contents| has not loaded, returns the default favicon. |
| 353 gfx::Image GetAppListIcon(content::WebContents* web_contents) const; |
| 354 |
| 355 // Get the title for the applicatoin list entry for |web_contents|. |
| 356 // If |web_contents| has not loaded, returns "Net Tab". |
| 357 string16 GetAppListTitle(content::WebContents* web_contents) const; |
| 358 |
| 359 // Overridden from chrome::BrowserListObserver. |
| 360 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
| 361 |
| 362 // Returns true when the given |browser| is listed in the browser application |
| 363 // list. |
| 364 bool IsBrowserRepresentedInBrowserList(Browser* browser); |
| 365 |
| 366 // Returns the LauncherItemController of BrowserShortcut. |
| 367 LauncherItemController* GetBrowserShortcutLauncherItemController(); |
284 | 368 |
285 protected: | 369 protected: |
286 friend class LauncherItemControllerPerAppTest; | |
287 friend class LauncherPlatformAppBrowserTest; | |
288 friend class LauncherAppBrowserTest; | |
289 // TODO(skuhne): Remove these when the old launcher get removed. | |
290 friend class LauncherPlatformPerAppAppBrowserTest; | |
291 friend class LauncherPerAppAppBrowserTest; | |
292 | |
293 // Creates a new app shortcut item and controller on the launcher at |index|. | 370 // Creates a new app shortcut item and controller on the launcher at |index|. |
294 // Use kInsertItemAtEnd to add a shortcut as the last item. | 371 // Use kInsertItemAtEnd to add a shortcut as the last item. |
295 virtual ash::LauncherID CreateAppShortcutLauncherItem( | 372 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& app_id, |
296 const std::string& app_id, | 373 int index); |
297 int index) = 0; | |
298 | 374 |
299 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. | 375 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. |
300 // These are intended for testing. | 376 // These are intended for testing. |
301 virtual void SetAppTabHelperForTest(AppTabHelper* helper) = 0; | 377 void SetAppTabHelperForTest(AppTabHelper* helper); |
302 virtual void SetAppIconLoaderForTest(extensions::AppIconLoader* loader) = 0; | 378 void SetAppIconLoaderForTest(extensions::AppIconLoader* loader); |
303 virtual const std::string& GetAppIdFromLauncherIdForTest( | 379 const std::string& GetAppIdFromLauncherIdForTest(ash::LauncherID id); |
304 ash::LauncherID id) = 0; | |
305 | 380 |
306 private: | 381 private: |
| 382 friend class ChromeLauncherControllerTest; |
| 383 friend class LauncherAppBrowserTest; |
| 384 friend class LauncherPlatformAppBrowserTest; |
| 385 |
| 386 typedef std::map<ash::LauncherID, LauncherItemController*> |
| 387 IDToItemControllerMap; |
| 388 typedef std::list<content::WebContents*> WebContentsList; |
| 389 typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; |
| 390 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; |
| 391 |
| 392 // Creates a new app shortcut item and controller on the launcher at |index|. |
| 393 // Use kInsertItemAtEnd to add a shortcut as the last item. |
| 394 ash::LauncherID CreateAppShortcutLauncherItemWithType( |
| 395 const std::string& app_id, |
| 396 int index, |
| 397 ash::LauncherItemType launcher_item_type); |
| 398 |
| 399 // Updates the activation state of the Broswer item. |
| 400 void UpdateBrowserItemStatus(); |
| 401 |
| 402 // Returns the profile used for new windows. |
| 403 Profile* GetProfileForNewWindows(); |
| 404 |
| 405 // Invoked when the associated browser or app is closed. |
| 406 void LauncherItemClosed(ash::LauncherID id); |
| 407 |
| 408 // Internal helpers for pinning and unpinning that handle both |
| 409 // client-triggered and internal pinning operations. |
| 410 void DoPinAppWithID(const std::string& app_id); |
| 411 void DoUnpinAppsWithID(const std::string& app_id); |
| 412 |
| 413 // Re-syncs launcher model with prefs::kPinnedLauncherApps. |
| 414 void UpdateAppLaunchersFromPref(); |
| 415 |
| 416 // Persists the shelf auto-hide behavior to prefs. |
| 417 void SetShelfAutoHideBehaviorPrefs(ash::ShelfAutoHideBehavior behavior, |
| 418 aura::RootWindow* root_window); |
| 419 |
| 420 // Sets the shelf auto-hide behavior from prefs. |
| 421 void SetShelfAutoHideBehaviorFromPrefs(); |
| 422 |
| 423 // Sets the shelf alignment from prefs. |
| 424 void SetShelfAlignmentFromPrefs(); |
| 425 |
| 426 // Sets both of auto-hide behavior and alignment from prefs. |
| 427 void SetShelfBehaviorsFromPrefs(); |
| 428 |
| 429 // Returns the most recently active web contents for an app. |
| 430 content::WebContents* GetLastActiveWebContents(const std::string& app_id); |
| 431 |
| 432 // Creates an app launcher to insert at |index|. Note that |index| may be |
| 433 // adjusted by the model to meet ordering constraints. |
| 434 // The |launcher_item_type| will be set into the LauncherModel. |
| 435 ash::LauncherID InsertAppLauncherItem( |
| 436 LauncherItemController* controller, |
| 437 const std::string& app_id, |
| 438 ash::LauncherItemStatus status, |
| 439 int index, |
| 440 ash::LauncherItemType launcher_item_type); |
| 441 |
| 442 bool HasItemController(ash::LauncherID id) const; |
| 443 |
| 444 // Enumerate all Web contents which match a given shortcut |controller|. |
| 445 std::vector<content::WebContents*> GetV1ApplicationsFromController( |
| 446 LauncherItemController* controller); |
| 447 |
| 448 // Create LauncherItem for Browser Shortcut. |
| 449 ash::LauncherID CreateBrowserShortcutLauncherItem(); |
| 450 |
| 451 // Check if the given |web_contents| is in incognito mode. |
| 452 bool IsIncognito(content::WebContents* web_contents) const; |
| 453 |
| 454 // Update browser shortcut's index. |
| 455 void PersistChromeItemIndex(int index); |
| 456 |
| 457 // Get browser shortcut's index from pref. |
| 458 int GetChromeIconIndexFromPref() const; |
| 459 |
| 460 // Close all windowed V1 applications of a certain extension which was already |
| 461 // deleted. |
| 462 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id); |
| 463 |
| 464 // Move a launcher item ignoring the pinned state changes from |index| to |
| 465 // |target_index|. |
| 466 void MoveItemWithoutPinnedStateChangeNotification(int source_index, |
| 467 int target_index); |
| 468 |
307 static ChromeLauncherController* instance_; | 469 static ChromeLauncherController* instance_; |
| 470 |
| 471 ash::LauncherModel* model_; |
| 472 |
| 473 // Profile used for prefs and loading extensions. This is NOT necessarily the |
| 474 // profile new windows are created with. |
| 475 Profile* profile_; |
| 476 |
| 477 IDToItemControllerMap id_to_item_controller_map_; |
| 478 |
| 479 // Maintains activation order of web contents for each app. |
| 480 AppIDToWebContentsListMap app_id_to_web_contents_list_; |
| 481 |
| 482 // Direct access to app_id for a web contents. |
| 483 WebContentsToAppIDMap web_contents_to_app_id_; |
| 484 |
| 485 // Used to track shell windows. |
| 486 scoped_ptr<ShellWindowLauncherController> shell_window_controller_; |
| 487 |
| 488 // Used to get app info for tabs. |
| 489 scoped_ptr<AppTabHelper> app_tab_helper_; |
| 490 |
| 491 // Used to load the image for an app item. |
| 492 scoped_ptr<extensions::AppIconLoader> app_icon_loader_; |
| 493 |
| 494 content::NotificationRegistrar notification_registrar_; |
| 495 |
| 496 PrefChangeRegistrar pref_change_registrar_; |
| 497 |
| 498 AppSyncUIState* app_sync_ui_state_; |
| 499 |
| 500 scoped_ptr<ExtensionEnableFlow> extension_enable_flow_; |
| 501 |
| 502 // Launchers that are currently being observed. |
| 503 std::set<ash::Launcher*> launchers_; |
| 504 |
| 505 // The owned browser shortcut item. |
| 506 scoped_ptr<BrowserShortcutLauncherItemController> browser_item_controller_; |
| 507 |
| 508 // If true, incoming pinned state changes should be ignored. |
| 509 bool ignore_persist_pinned_state_change_; |
| 510 |
| 511 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
308 }; | 512 }; |
309 | 513 |
310 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 514 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
OLD | NEW |