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_PER_APP_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_APP_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "ash/display/display_controller.h" | 14 #include "ash/display/display_controller.h" |
| 15 #include "ash/launcher/launcher_delegate.h" |
15 #include "ash/launcher/launcher_model_observer.h" | 16 #include "ash/launcher/launcher_model_observer.h" |
16 #include "ash/launcher/launcher_types.h" | 17 #include "ash/launcher/launcher_types.h" |
17 #include "ash/shelf/shelf_layout_manager_observer.h" | 18 #include "ash/shelf/shelf_layout_manager_observer.h" |
18 #include "ash/shelf/shelf_types.h" | 19 #include "ash/shelf/shelf_types.h" |
19 #include "ash/shell_observer.h" | 20 #include "ash/shell_observer.h" |
20 #include "base/basictypes.h" | 21 #include "base/basictypes.h" |
21 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
22 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
23 #include "base/memory/scoped_vector.h" | 24 #include "base/memory/scoped_vector.h" |
24 #include "base/prefs/pref_change_registrar.h" | 25 #include "base/prefs/pref_change_registrar.h" |
| 26 #include "chrome/browser/extensions/app_icon_loader.h" |
25 #include "chrome/browser/extensions/extension_prefs.h" | 27 #include "chrome/browser/extensions/extension_prefs.h" |
26 #include "chrome/browser/prefs/pref_service_syncable_observer.h" | 28 #include "chrome/browser/prefs/pref_service_syncable_observer.h" |
27 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" | 29 #include "chrome/browser/ui/ash/app_sync_ui_state_observer.h" |
28 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 30 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
29 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | |
30 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_controller.h" | |
31 #include "chrome/browser/ui/browser_list_observer.h" | 31 #include "chrome/browser/ui/browser_list_observer.h" |
32 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" | 32 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" |
33 #include "content/public/browser/notification_observer.h" | 33 #include "content/public/browser/notification_observer.h" |
34 #include "content/public/browser/notification_registrar.h" | |
35 #include "ui/aura/window_observer.h" | 34 #include "ui/aura/window_observer.h" |
36 | 35 |
37 class AppSyncUIState; | 36 class AppSyncUIState; |
38 class Browser; | 37 class Browser; |
39 class BrowserLauncherItemControllerTest; | |
40 class BrowserShortcutLauncherItemController; | 38 class BrowserShortcutLauncherItemController; |
41 class ExtensionEnableFlow; | 39 class ExtensionEnableFlow; |
| 40 class GURL; |
42 class LauncherItemController; | 41 class LauncherItemController; |
43 class Profile; | 42 class Profile; |
| 43 class ShellWindowLauncherController; |
44 class TabContents; | 44 class TabContents; |
45 | 45 |
46 namespace ash { | 46 namespace ash { |
47 class LauncherModel; | 47 class LauncherModel; |
48 } | 48 } |
49 | 49 |
50 namespace aura { | 50 namespace aura { |
51 class Window; | 51 class Window; |
52 } | 52 } |
53 | 53 |
54 namespace content { | 54 namespace content { |
| 55 class NotificationRegistrar; |
55 class WebContents; | 56 class WebContents; |
56 } | 57 } |
57 | 58 |
58 namespace ui { | 59 namespace ui { |
59 class BaseWindow; | 60 class BaseWindow; |
60 } | 61 } |
61 | 62 |
62 // ChromeLauncherControllerPerApp manages the launcher items needed for content | 63 // A list of the elements which makes up a simple menu description. |
63 // content windows. Launcher items have a type, an optional app id, and a | 64 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; |
64 // controller. This incarnation groups running tabs/windows in application | 65 |
65 // specific lists. | 66 // ChromeLauncherController manages the launcher items needed for content |
66 // * Tabbed browsers and browser app windows have BrowserLauncherItemController, | 67 // windows. Launcher items have a type, an optional app id, and a controller. |
67 // owned by the BrowserView instance. | 68 // This incarnation groups running tabs/windows in application specific lists. |
| 69 // * Browser app windows have BrowserLauncherItemController, owned by the |
| 70 // BrowserView instance. |
68 // * App shell windows have ShellWindowLauncherItemController, owned by | 71 // * App shell windows have ShellWindowLauncherItemController, owned by |
69 // ShellWindowLauncherController. | 72 // ShellWindowLauncherController. |
70 // * Shortcuts have no LauncherItemController. | 73 // * Shortcuts have no LauncherItemController. |
71 class ChromeLauncherControllerPerApp | 74 class ChromeLauncherController : public ash::LauncherDelegate, |
72 : public ash::LauncherModelObserver, | 75 public ash::LauncherModelObserver, |
73 public ash::ShellObserver, | 76 public ash::ShellObserver, |
74 public ash::DisplayController::Observer, | 77 public ash::DisplayController::Observer, |
75 public ChromeLauncherController, | 78 public content::NotificationObserver, |
76 public content::NotificationObserver, | 79 public extensions::AppIconLoader::Delegate, |
77 public PrefServiceSyncableObserver, | 80 public PrefServiceSyncableObserver, |
78 public AppSyncUIStateObserver, | 81 public AppSyncUIStateObserver, |
79 public ExtensionEnableFlowDelegate, | 82 public ExtensionEnableFlowDelegate, |
80 public chrome::BrowserListObserver, | 83 public chrome::BrowserListObserver, |
81 public ash::ShelfLayoutManagerObserver { | 84 public ash::ShelfLayoutManagerObserver { |
82 public: | 85 public: |
83 ChromeLauncherControllerPerApp(Profile* profile, ash::LauncherModel* model); | 86 // Indicates if a launcher item is incognito or not. |
84 virtual ~ChromeLauncherControllerPerApp(); | 87 enum IncognitoState { |
85 | 88 STATE_INCOGNITO, |
86 // ChromeLauncherController overrides: | 89 STATE_NOT_INCOGNITO, |
87 | 90 }; |
88 // Initializes this ChromeLauncherControllerPerApp. | 91 |
89 virtual void Init() OVERRIDE; | 92 // Used to update the state of non plaform apps, as web contents change. |
90 | 93 enum AppState { |
91 // Returns the new per application interface of the given launcher. If it is | 94 APP_STATE_ACTIVE, |
92 // a per browser (old) controller, it will return NULL; | 95 APP_STATE_WINDOW_ACTIVE, |
93 // TODO(skuhne): Remove when we rip out the old launcher. | 96 APP_STATE_INACTIVE, |
94 virtual ChromeLauncherControllerPerApp* GetPerAppInterface() OVERRIDE; | 97 APP_STATE_REMOVED |
95 | 98 }; |
96 // Creates a new tabbed item on the launcher for |controller|. | 99 |
97 virtual ash::LauncherID CreateTabbedLauncherItem( | 100 // Mockable interface to get app ids from tabs. |
98 LauncherItemController* controller, | 101 class AppTabHelper { |
99 IncognitoState is_incognito, | 102 public: |
100 ash::LauncherItemStatus status) OVERRIDE; | 103 virtual ~AppTabHelper() {} |
| 104 |
| 105 // Returns the app id of the specified tab, or an empty string if there is |
| 106 // no app. |
| 107 virtual std::string GetAppID(content::WebContents* tab) = 0; |
| 108 |
| 109 // Returns true if |id| is valid. Used during restore to ignore no longer |
| 110 // valid extensions. |
| 111 virtual bool IsValidID(const std::string& id) = 0; |
| 112 }; |
| 113 |
| 114 ChromeLauncherController(Profile* profile, ash::LauncherModel* model); |
| 115 virtual ~ChromeLauncherController(); |
| 116 |
| 117 // Initializes this ChromeLauncherController. |
| 118 void Init(); |
| 119 |
| 120 // Creates an instance. |
| 121 static ChromeLauncherController* CreateInstance(Profile* profile, |
| 122 ash::LauncherModel* model); |
| 123 |
| 124 // Returns the single ChromeLauncherController instance. |
| 125 static ChromeLauncherController* instance() { return instance_; } |
101 | 126 |
102 // Creates a new app item on the launcher for |controller|. | 127 // Creates a new app item on the launcher for |controller|. |
103 virtual ash::LauncherID CreateAppLauncherItem( | 128 ash::LauncherID CreateAppLauncherItem(LauncherItemController* controller, |
104 LauncherItemController* controller, | 129 const std::string& app_id, |
105 const std::string& app_id, | 130 ash::LauncherItemStatus status); |
106 ash::LauncherItemStatus status) OVERRIDE; | |
107 | 131 |
108 // Updates the running status of an item. It will also update the status of | 132 // Updates the running status of an item. It will also update the status of |
109 // browsers launcher item if needed. | 133 // browsers launcher item if needed. |
110 virtual void SetItemStatus(ash::LauncherID id, | 134 void SetItemStatus(ash::LauncherID id, ash::LauncherItemStatus status); |
111 ash::LauncherItemStatus status) OVERRIDE; | |
112 | 135 |
113 // Updates the controller associated with id (which should be a shortcut). | 136 // Updates the controller associated with id (which should be a shortcut). |
114 // |controller| remains owned by caller. | 137 // |controller| remains owned by caller. |
115 virtual void SetItemController(ash::LauncherID id, | 138 void SetItemController(ash::LauncherID id, |
116 LauncherItemController* controller) OVERRIDE; | 139 LauncherItemController* controller); |
117 | 140 |
118 // Closes or unpins the launcher item. | 141 // Closes or unpins the launcher item. |
119 virtual void CloseLauncherItem(ash::LauncherID id) OVERRIDE; | 142 void CloseLauncherItem(ash::LauncherID id); |
120 | 143 |
121 // Pins the specified id. Currently only supports platform apps. | 144 // Pins the specified id. Currently only supports platform apps. |
122 virtual void Pin(ash::LauncherID id) OVERRIDE; | 145 void Pin(ash::LauncherID id); |
123 | 146 |
124 // Unpins the specified id, closing if not running. | 147 // Unpins the specified id, closing if not running. |
125 virtual void Unpin(ash::LauncherID id) OVERRIDE; | 148 void Unpin(ash::LauncherID id); |
126 | 149 |
127 // Returns true if the item identified by |id| is pinned. | 150 // Returns true if the item identified by |id| is pinned. |
128 virtual bool IsPinned(ash::LauncherID id) OVERRIDE; | 151 bool IsPinned(ash::LauncherID id); |
129 | 152 |
130 // Pins/unpins the specified id. | 153 // Pins/unpins the specified id. |
131 virtual void TogglePinned(ash::LauncherID id) OVERRIDE; | 154 void TogglePinned(ash::LauncherID id); |
132 | 155 |
133 // 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 |
134 // be pinned. | 157 // be pinned. |
135 virtual bool IsPinnable(ash::LauncherID id) const OVERRIDE; | 158 bool IsPinnable(ash::LauncherID id) const; |
136 | 159 |
137 // 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 |
138 // gets created. The (existing or created) launcher items get then locked | 161 // gets created. The (existing or created) launcher items get then locked |
139 // against a users un-pinning removal. | 162 // against a users un-pinning removal. |
140 virtual void LockV1AppWithID(const std::string& app_id) OVERRIDE; | 163 void LockV1AppWithID(const std::string& app_id); |
141 | 164 |
142 // 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 |
143 // 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. |
144 virtual void UnlockV1AppWithID(const std::string& app_id) OVERRIDE; | 167 void UnlockV1AppWithID(const std::string& app_id); |
145 | 168 |
146 // 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 |
147 // 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 |
148 // triggered this command. | 171 // triggered this command. |
149 virtual void Launch(ash::LauncherID id, int event_flags) OVERRIDE; | 172 void Launch(ash::LauncherID id, int event_flags); |
150 | 173 |
151 // Closes the specified item. | 174 // Closes the specified item. |
152 virtual void Close(ash::LauncherID id) OVERRIDE; | 175 void Close(ash::LauncherID id); |
153 | 176 |
154 // Returns true if the specified item is open. | 177 // Returns true if the specified item is open. |
155 virtual bool IsOpen(ash::LauncherID id) OVERRIDE; | 178 bool IsOpen(ash::LauncherID id); |
156 | 179 |
157 // Returns true if the specified item is for a platform app. | 180 // Returns true if the specified item is for a platform app. |
158 virtual bool IsPlatformApp(ash::LauncherID id) OVERRIDE; | 181 bool IsPlatformApp(ash::LauncherID id); |
159 | 182 |
160 // Opens a new instance of the application identified by |app_id|. | 183 // Opens a new instance of the application identified by |app_id|. |
161 // Used by the app-list, and by pinned-app launcher items. | 184 // Used by the app-list, and by pinned-app launcher items. |
162 virtual void LaunchApp(const std::string& app_id, int event_flags) OVERRIDE; | 185 void LaunchApp(const std::string& app_id, int event_flags); |
163 | 186 |
164 // 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, |
165 // otherwise launches and activates the app. | 188 // otherwise launches and activates the app. |
166 // Used by the app-list, and by pinned-app launcher items. | 189 // Used by the app-list, and by pinned-app launcher items. |
167 virtual void ActivateApp(const std::string& app_id, int event_flags) OVERRIDE; | 190 void ActivateApp(const std::string& app_id, int event_flags); |
168 | 191 |
169 // Returns the launch type of app for the specified id. | 192 // Returns the launch type of app for the specified id. |
170 virtual extensions::ExtensionPrefs::LaunchType GetLaunchType( | 193 extensions::ExtensionPrefs::LaunchType GetLaunchType(ash::LauncherID id); |
171 ash::LauncherID id) OVERRIDE; | |
172 | 194 |
173 // Returns the id of the app for the specified tab. | 195 // Returns the id of the app for the specified tab. |
174 virtual std::string GetAppID(content::WebContents* tab) OVERRIDE; | 196 std::string GetAppID(content::WebContents* tab); |
175 | 197 |
176 // Returns the |LauncherModel|'s ID or 0 if the AppId was not found. | 198 std::string GetAppIDForLauncherID(ash::LauncherID id); |
177 virtual ash::LauncherID GetLauncherIDForAppID( | |
178 const std::string& app_id) OVERRIDE; | |
179 virtual std::string GetAppIDForLauncherID(ash::LauncherID id) OVERRIDE; | |
180 | 199 |
181 // 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). |
182 virtual void SetLauncherItemImage(ash::LauncherID launcher_id, | 201 void SetLauncherItemImage(ash::LauncherID launcher_id, |
183 const gfx::ImageSkia& image) OVERRIDE; | 202 const gfx::ImageSkia& image); |
184 | |
185 // Returns true if a pinned launcher item with given |app_id| could be found. | |
186 virtual bool IsAppPinned(const std::string& app_id) OVERRIDE; | |
187 | 203 |
188 // Find out if the given application |id| is a windowed app item and not a | 204 // Find out if the given application |id| is a windowed app item and not a |
189 // pinned item in the launcher. | 205 // pinned item in the launcher. |
190 bool IsWindowedAppInLauncher(const std::string& app_id); | 206 bool IsWindowedAppInLauncher(const std::string& app_id); |
191 | 207 |
192 // Pins an app with |app_id| to launcher. If there is a running instance in | |
193 // launcher, the running instance is pinned. If there is no running instance, | |
194 // a new launcher item is created and pinned. | |
195 virtual void PinAppWithID(const std::string& app_id) OVERRIDE; | |
196 | |
197 // 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|. |
198 virtual void SetLaunchType( | 209 void SetLaunchType(ash::LauncherID id, |
199 ash::LauncherID id, | 210 extensions::ExtensionPrefs::LaunchType launch_type); |
200 extensions::ExtensionPrefs::LaunchType launch_type) OVERRIDE; | |
201 | |
202 // Unpins any app items whose id is |app_id|. | |
203 virtual void UnpinAppsWithID(const std::string& app_id) OVERRIDE; | |
204 | 211 |
205 // 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. |
206 virtual bool IsLoggedInAsGuest() OVERRIDE; | 213 // Makes virtual for unittest in LauncherContextMenuTest. |
| 214 virtual bool IsLoggedInAsGuest(); |
207 | 215 |
208 // 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 |
209 // used window (or CTRL is held with the click). | 217 // used window (or CTRL is held with the click). |
210 virtual void CreateNewWindow() OVERRIDE; | 218 void CreateNewWindow(); |
211 | 219 |
212 // 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 |
213 // incognito window. | 221 // incognito window. |
214 virtual void CreateNewIncognitoWindow() OVERRIDE; | 222 void CreateNewIncognitoWindow(); |
215 | 223 |
216 // 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 |
217 // 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. |
218 virtual bool CanPin() const OVERRIDE; | 226 bool CanPin() const; |
219 | 227 |
220 // 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. |
221 // 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 |
222 // id of the app. | 230 // id of the app. |
223 virtual void PersistPinnedState() OVERRIDE; | 231 void PersistPinnedState(); |
224 | 232 |
225 virtual ash::LauncherModel* model() OVERRIDE; | 233 ash::LauncherModel* model(); |
226 | 234 |
227 virtual Profile* profile() OVERRIDE; | 235 Profile* profile(); |
228 | 236 |
229 // Gets the shelf auto-hide behavior on |root_window|. | 237 // Gets the shelf auto-hide behavior on |root_window|. |
230 virtual ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( | 238 ash::ShelfAutoHideBehavior GetShelfAutoHideBehavior( |
231 aura::RootWindow* root_window) const OVERRIDE; | 239 aura::RootWindow* root_window) const; |
232 | 240 |
233 // 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 |
234 // behavior on |root_window|. | 242 // behavior on |root_window|. |
235 virtual bool CanUserModifyShelfAutoHideBehavior( | 243 bool CanUserModifyShelfAutoHideBehavior(aura::RootWindow* root_window) const; |
236 aura::RootWindow* root_window) const OVERRIDE; | |
237 | 244 |
238 // 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 |
239 // user is not allowed to modify the auto-hide behavior. | 246 // user is not allowed to modify the auto-hide behavior. |
240 virtual void ToggleShelfAutoHideBehavior( | 247 void ToggleShelfAutoHideBehavior(aura::RootWindow* root_window); |
241 aura::RootWindow* root_window) OVERRIDE; | |
242 | 248 |
243 // The tab no longer represents its previously identified application. | 249 // The tab no longer represents its previously identified application. |
244 virtual void RemoveTabFromRunningApp(content::WebContents* tab, | 250 void RemoveTabFromRunningApp(content::WebContents* tab, |
245 const std::string& app_id) OVERRIDE; | 251 const std::string& app_id); |
246 | 252 |
247 // 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 |
248 // have changed, | 254 // have changed, |
249 virtual void UpdateAppState(content::WebContents* contents, | 255 void UpdateAppState(content::WebContents* contents, AppState app_state); |
250 AppState app_state) OVERRIDE; | |
251 | 256 |
252 // Limits application refocusing to urls that match |url| for |id|. | 257 // Limits application refocusing to urls that match |url| for |id|. |
253 virtual void SetRefocusURLPatternForTest(ash::LauncherID id, | 258 void SetRefocusURLPatternForTest(ash::LauncherID id, const GURL& url); |
254 const GURL& url) OVERRIDE; | |
255 | 259 |
256 // Returns the extension identified by |app_id|. | 260 // Returns the extension identified by |app_id|. |
257 virtual const extensions::Extension* GetExtensionForAppID( | 261 const extensions::Extension* GetExtensionForAppID( |
258 const std::string& app_id) const OVERRIDE; | 262 const std::string& app_id) const; |
259 | 263 |
260 // 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 |
261 // it, the the window will get minimized instead. | 265 // it, the the window will get minimized instead. |
262 virtual void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, | 266 void ActivateWindowOrMinimizeIfActive(ui::BaseWindow* window, |
263 bool allow_minimize) OVERRIDE; | 267 bool allow_minimize); |
264 | 268 |
265 // ash::LauncherDelegate overrides: | 269 // ash::LauncherDelegate overrides: |
266 virtual void ItemSelected(const ash::LauncherItem& item, | 270 virtual void ItemSelected(const ash::LauncherItem& item, |
267 const ui::Event& event) OVERRIDE; | 271 const ui::Event& event) OVERRIDE; |
268 virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE; | 272 virtual string16 GetTitle(const ash::LauncherItem& item) OVERRIDE; |
269 virtual ui::MenuModel* CreateContextMenu( | 273 virtual ui::MenuModel* CreateContextMenu( |
270 const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE; | 274 const ash::LauncherItem& item, aura::RootWindow* root) OVERRIDE; |
271 virtual ash::LauncherMenuModel* CreateApplicationMenu( | 275 virtual ash::LauncherMenuModel* CreateApplicationMenu( |
272 const ash::LauncherItem& item, | 276 const ash::LauncherItem& item, |
273 int event_flags) OVERRIDE; | 277 int event_flags) OVERRIDE; |
274 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; | 278 virtual ash::LauncherID GetIDByWindow(aura::Window* window) OVERRIDE; |
275 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; | 279 virtual bool IsDraggable(const ash::LauncherItem& item) OVERRIDE; |
276 virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE; | 280 virtual bool ShouldShowTooltip(const ash::LauncherItem& item) OVERRIDE; |
277 virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; | 281 virtual void OnLauncherCreated(ash::Launcher* launcher) OVERRIDE; |
278 virtual void OnLauncherDestroyed(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; |
279 | 288 |
280 // ash::LauncherModelObserver overrides: | 289 // ash::LauncherModelObserver overrides: |
281 virtual void LauncherItemAdded(int index) OVERRIDE; | 290 virtual void LauncherItemAdded(int index) OVERRIDE; |
282 virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; | 291 virtual void LauncherItemRemoved(int index, ash::LauncherID id) OVERRIDE; |
283 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; | 292 virtual void LauncherItemMoved(int start_index, int target_index) OVERRIDE; |
284 virtual void LauncherItemChanged(int index, | 293 virtual void LauncherItemChanged(int index, |
285 const ash::LauncherItem& old_item) OVERRIDE; | 294 const ash::LauncherItem& old_item) OVERRIDE; |
286 virtual void LauncherStatusChanged() OVERRIDE; | 295 virtual void LauncherStatusChanged() OVERRIDE; |
287 | 296 |
288 // content::NotificationObserver overrides: | 297 // content::NotificationObserver overrides: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 360 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
352 | 361 |
353 // Returns true when the given |browser| is listed in the browser application | 362 // Returns true when the given |browser| is listed in the browser application |
354 // list. | 363 // list. |
355 bool IsBrowserRepresentedInBrowserList(Browser* browser); | 364 bool IsBrowserRepresentedInBrowserList(Browser* browser); |
356 | 365 |
357 // Returns the LauncherItemController of BrowserShortcut. | 366 // Returns the LauncherItemController of BrowserShortcut. |
358 LauncherItemController* GetBrowserShortcutLauncherItemController(); | 367 LauncherItemController* GetBrowserShortcutLauncherItemController(); |
359 | 368 |
360 protected: | 369 protected: |
361 // ChromeLauncherController overrides: | |
362 | |
363 // 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|. |
364 // Use kInsertItemAtEnd to add a shortcut as the last item. | 371 // Use kInsertItemAtEnd to add a shortcut as the last item. |
365 virtual ash::LauncherID CreateAppShortcutLauncherItem( | 372 ash::LauncherID CreateAppShortcutLauncherItem(const std::string& app_id, |
366 const std::string& app_id, | 373 int index); |
367 int index) OVERRIDE; | |
368 | 374 |
369 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. | 375 // Sets the AppTabHelper/AppIconLoader, taking ownership of the helper class. |
370 // These are intended for testing. | 376 // These are intended for testing. |
371 virtual void SetAppTabHelperForTest(AppTabHelper* helper) OVERRIDE; | 377 void SetAppTabHelperForTest(AppTabHelper* helper); |
372 virtual void SetAppIconLoaderForTest( | 378 void SetAppIconLoaderForTest(extensions::AppIconLoader* loader); |
373 extensions::AppIconLoader* loader) OVERRIDE; | 379 const std::string& GetAppIdFromLauncherIdForTest(ash::LauncherID id); |
374 virtual const std::string& GetAppIdFromLauncherIdForTest( | |
375 ash::LauncherID id) OVERRIDE; | |
376 | 380 |
377 private: | 381 private: |
378 friend class ChromeLauncherControllerPerAppTest; | 382 friend class ChromeLauncherControllerTest; |
379 friend class LauncherPerAppAppBrowserTest; | 383 friend class LauncherAppBrowserTest; |
380 friend class LauncherPlatformPerAppAppBrowserTest; | 384 friend class LauncherPlatformAppBrowserTest; |
381 | |
382 // Creates a new app shortcut item and controller on the launcher at |index|. | |
383 // Use kInsertItemAtEnd to add a shortcut as the last item. | |
384 virtual ash::LauncherID CreateAppShortcutLauncherItemWithType( | |
385 const std::string& app_id, | |
386 int index, | |
387 ash::LauncherItemType launcher_item_type); | |
388 | |
389 // Updates the activation state of the Broswer item. | |
390 void UpdateBrowserItemStatus(); | |
391 | 385 |
392 typedef std::map<ash::LauncherID, LauncherItemController*> | 386 typedef std::map<ash::LauncherID, LauncherItemController*> |
393 IDToItemControllerMap; | 387 IDToItemControllerMap; |
394 typedef std::list<content::WebContents*> WebContentsList; | 388 typedef std::list<content::WebContents*> WebContentsList; |
395 typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; | 389 typedef std::map<std::string, WebContentsList> AppIDToWebContentsListMap; |
396 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; | 390 typedef std::map<content::WebContents*, std::string> WebContentsToAppIDMap; |
397 | 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 |
398 // Returns the profile used for new windows. | 402 // Returns the profile used for new windows. |
399 Profile* GetProfileForNewWindows(); | 403 Profile* GetProfileForNewWindows(); |
400 | 404 |
401 // Invoked when the associated browser or app is closed. | 405 // Invoked when the associated browser or app is closed. |
402 void LauncherItemClosed(ash::LauncherID id); | 406 void LauncherItemClosed(ash::LauncherID id); |
403 | 407 |
404 // Internal helpers for pinning and unpinning that handle both | 408 // Internal helpers for pinning and unpinning that handle both |
405 // client-triggered and internal pinning operations. | 409 // client-triggered and internal pinning operations. |
406 void DoPinAppWithID(const std::string& app_id); | 410 void DoPinAppWithID(const std::string& app_id); |
407 void DoUnpinAppsWithID(const std::string& app_id); | 411 void DoUnpinAppsWithID(const std::string& app_id); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 459 |
456 // Close all windowed V1 applications of a certain extension which was already | 460 // Close all windowed V1 applications of a certain extension which was already |
457 // deleted. | 461 // deleted. |
458 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id); | 462 void CloseWindowedAppsFromRemovedExtension(const std::string& app_id); |
459 | 463 |
460 // Move a launcher item ignoring the pinned state changes from |index| to | 464 // Move a launcher item ignoring the pinned state changes from |index| to |
461 // |target_index|. | 465 // |target_index|. |
462 void MoveItemWithoutPinnedStateChangeNotification(int source_index, | 466 void MoveItemWithoutPinnedStateChangeNotification(int source_index, |
463 int target_index); | 467 int target_index); |
464 | 468 |
| 469 static ChromeLauncherController* instance_; |
| 470 |
465 ash::LauncherModel* model_; | 471 ash::LauncherModel* model_; |
466 | 472 |
467 // Profile used for prefs and loading extensions. This is NOT necessarily the | 473 // Profile used for prefs and loading extensions. This is NOT necessarily the |
468 // profile new windows are created with. | 474 // profile new windows are created with. |
469 Profile* profile_; | 475 Profile* profile_; |
470 | 476 |
471 IDToItemControllerMap id_to_item_controller_map_; | 477 IDToItemControllerMap id_to_item_controller_map_; |
472 | 478 |
473 // Maintains activation order of web contents for each app. | 479 // Maintains activation order of web contents for each app. |
474 AppIDToWebContentsListMap app_id_to_web_contents_list_; | 480 AppIDToWebContentsListMap app_id_to_web_contents_list_; |
(...skipping 20 matching lines...) Expand all Loading... |
495 | 501 |
496 // Launchers that are currently being observed. | 502 // Launchers that are currently being observed. |
497 std::set<ash::Launcher*> launchers_; | 503 std::set<ash::Launcher*> launchers_; |
498 | 504 |
499 // The owned browser shortcut item. | 505 // The owned browser shortcut item. |
500 scoped_ptr<BrowserShortcutLauncherItemController> browser_item_controller_; | 506 scoped_ptr<BrowserShortcutLauncherItemController> browser_item_controller_; |
501 | 507 |
502 // If true, incoming pinned state changes should be ignored. | 508 // If true, incoming pinned state changes should be ignored. |
503 bool ignore_persist_pinned_state_change_; | 509 bool ignore_persist_pinned_state_change_; |
504 | 510 |
505 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerPerApp); | 511 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
506 }; | 512 }; |
507 | 513 |
508 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_PER_APP_H_ | 514 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
OLD | NEW |