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 <memory> | |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "ash/common/shelf/shelf_item_delegate.h" | 12 #include "ash/common/shelf/shelf_item_delegate.h" |
12 #include "ash/common/shelf/shelf_item_types.h" | 13 #include "ash/common/shelf/shelf_item_types.h" |
14 #include "ash/public/interfaces/shelf.mojom.h" | |
13 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "chrome/browser/ui/app_icon_loader.h" | |
17 #include "chrome/browser/ui/app_icon_loader_delegate.h" | |
14 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 18 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" | 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_types.h" |
17 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h" | 21 #include "chrome/browser/ui/ash/launcher/settings_window_observer.h" |
18 #include "extensions/common/constants.h" | 22 #include "extensions/common/constants.h" |
23 #include "mojo/public/cpp/bindings/associated_binding.h" | |
19 | 24 |
20 class AccountId; | 25 class AccountId; |
21 class ArcAppDeferredLauncherController; | 26 class ArcAppDeferredLauncherController; |
22 class Browser; | 27 class Browser; |
23 class BrowserShortcutLauncherItemController; | 28 class BrowserShortcutLauncherItemController; |
24 class GURL; | 29 class GURL; |
30 class LauncherControllerHelper; | |
25 class LauncherItemController; | 31 class LauncherItemController; |
26 | 32 |
27 namespace ash { | 33 namespace ash { |
28 class WmShelf; | 34 class WmShelf; |
29 } | 35 } |
30 | 36 |
31 namespace content { | 37 namespace content { |
32 class WebContents; | 38 class WebContents; |
33 } | 39 } |
34 | 40 |
35 namespace gfx { | 41 namespace gfx { |
36 class Image; | 42 class Image; |
37 } | 43 } |
38 | 44 |
39 namespace ui { | 45 namespace ui { |
40 class BaseWindow; | 46 class BaseWindow; |
41 } | 47 } |
42 | 48 |
43 // A list of the elements which makes up a simple menu description. | 49 // A list of the elements which makes up a simple menu description. |
44 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; | 50 typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; |
45 | 51 |
46 // ChromeLauncherController manages the launcher items needed for content | 52 // ChromeLauncherController manages the launcher items needed for content |
47 // windows. Launcher items have a type, an optional app id, and a controller. | 53 // windows. Launcher items have a type, an optional app id, and a controller. |
48 // There are different kinds of launcher item controllers, all extending the | 54 // Implements mojom::ShelfObserver and is a client of mojom::ShelfController. |
49 // LauncherItemController class. | 55 class ChromeLauncherController : public ash::mojom::ShelfObserver, |
50 class ChromeLauncherController { | 56 public AppIconLoaderDelegate { |
51 public: | 57 public: |
52 // Used to update the state of non plaform apps, as web contents change. | 58 // Used to update the state of non plaform apps, as web contents change. |
53 enum AppState { | 59 enum AppState { |
54 APP_STATE_ACTIVE, | 60 APP_STATE_ACTIVE, |
55 APP_STATE_WINDOW_ACTIVE, | 61 APP_STATE_WINDOW_ACTIVE, |
56 APP_STATE_INACTIVE, | 62 APP_STATE_INACTIVE, |
57 APP_STATE_REMOVED | 63 APP_STATE_REMOVED |
58 }; | 64 }; |
59 | 65 |
60 // Set the ChromeLauncherController singleton. | 66 // Returns the single ChromeLauncherController instance. |
61 static void set_instance(ChromeLauncherController* instance) { | 67 static ChromeLauncherController* instance() { return instance_; } |
68 static void set_instance_for_test(ChromeLauncherController* instance) { | |
sky
2016/10/11 02:40:37
optional: I'm not a fan of polluting public API wi
msw
2016/10/11 15:38:00
Added a TODO; it's a temporary workaround for crbu
| |
62 instance_ = instance; | 69 instance_ = instance; |
63 } | 70 } |
64 | 71 |
65 // Returns the single ChromeLauncherController instance. | 72 Profile* profile() const { return profile_; } |
66 static ChromeLauncherController* instance() { return instance_; } | |
67 | 73 |
68 virtual ~ChromeLauncherController(); | 74 LauncherControllerHelper* launcher_controller_helper() { |
75 return launcher_controller_helper_.get(); | |
76 } | |
77 | |
78 ~ChromeLauncherController() override; | |
69 | 79 |
70 // Initializes this ChromeLauncherController. | 80 // Initializes this ChromeLauncherController. |
71 virtual void Init() = 0; | 81 virtual void Init() = 0; |
72 | 82 |
73 // Creates a new app item on the shelf for |controller|. | 83 // Creates a new app item on the shelf for |controller|. |
74 virtual ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, | 84 virtual ash::ShelfID CreateAppLauncherItem(LauncherItemController* controller, |
75 const std::string& app_id, | 85 const std::string& app_id, |
76 ash::ShelfItemStatus status) = 0; | 86 ash::ShelfItemStatus status) = 0; |
77 | 87 |
78 // Updates the running status of an item. It will also update the status of | 88 // Updates the running status of an item. It will also update the status of |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 virtual void Close(ash::ShelfID id) = 0; | 132 virtual void Close(ash::ShelfID id) = 0; |
123 | 133 |
124 // Returns true if the specified item is open. | 134 // Returns true if the specified item is open. |
125 virtual bool IsOpen(ash::ShelfID id) = 0; | 135 virtual bool IsOpen(ash::ShelfID id) = 0; |
126 | 136 |
127 // Returns true if the specified item is for a platform app. | 137 // Returns true if the specified item is for a platform app. |
128 virtual bool IsPlatformApp(ash::ShelfID id) = 0; | 138 virtual bool IsPlatformApp(ash::ShelfID id) = 0; |
129 | 139 |
130 // Opens a new instance of the application identified by |app_id|. | 140 // Opens a new instance of the application identified by |app_id|. |
131 // Used by the app-list, and by pinned-app shelf items. | 141 // Used by the app-list, and by pinned-app shelf items. |
132 virtual void LaunchApp(const std::string& app_id, | 142 void LaunchApp(const std::string& app_id, |
133 ash::LaunchSource source, | 143 ash::LaunchSource source, |
134 int event_flags) = 0; | 144 int event_flags); |
135 | 145 |
136 // If |app_id| is running, reactivates the app's most recently active window, | 146 // If |app_id| is running, reactivates the app's most recently active window, |
137 // otherwise launches and activates the app. | 147 // otherwise launches and activates the app. |
138 // Used by the app-list, and by pinned-app shelf items. | 148 // Used by the app-list, and by pinned-app shelf items. |
139 virtual void ActivateApp(const std::string& app_id, | 149 virtual void ActivateApp(const std::string& app_id, |
140 ash::LaunchSource source, | 150 ash::LaunchSource source, |
141 int event_flags) = 0; | 151 int event_flags) = 0; |
142 | 152 |
143 // Returns the launch type of app for the specified id. | 153 // Returns the launch type of app for the specified id. |
144 virtual extensions::LaunchType GetLaunchType(ash::ShelfID id) = 0; | 154 virtual extensions::LaunchType GetLaunchType(ash::ShelfID id) = 0; |
145 | 155 |
146 // Set the image for a specific shelf item (e.g. when set by the app). | 156 // Set the image for a specific shelf item (e.g. when set by the app). |
147 virtual void SetLauncherItemImage(ash::ShelfID shelf_id, | 157 virtual void SetLauncherItemImage(ash::ShelfID shelf_id, |
148 const gfx::ImageSkia& image) = 0; | 158 const gfx::ImageSkia& image) = 0; |
149 | 159 |
150 // Find out if the given application |id| is a windowed app item and not a | 160 // Find out if the given application |id| is a windowed app item and not a |
151 // pinned item in the shelf. | 161 // pinned item in the shelf. |
152 virtual bool IsWindowedAppInLauncher(const std::string& app_id) = 0; | 162 virtual bool IsWindowedAppInLauncher(const std::string& app_id) = 0; |
153 | 163 |
154 // Updates the launch type of the app for the specified id to |launch_type|. | 164 // Updates the launch type of the app for the specified id to |launch_type|. |
155 virtual void SetLaunchType(ash::ShelfID id, | 165 virtual void SetLaunchType(ash::ShelfID id, |
156 extensions::LaunchType launch_type) = 0; | 166 extensions::LaunchType launch_type) = 0; |
157 | 167 |
158 // Accessor to the currently loaded profile. Note that in multi profile use | |
159 // cases this might change over time. | |
160 virtual Profile* GetProfile() = 0; | |
161 | |
162 // Notify the controller that the state of an non platform app's tabs | 168 // Notify the controller that the state of an non platform app's tabs |
163 // have changed, | 169 // have changed, |
164 virtual void UpdateAppState(content::WebContents* contents, | 170 virtual void UpdateAppState(content::WebContents* contents, |
165 AppState app_state) = 0; | 171 AppState app_state) = 0; |
166 | 172 |
167 // Returns ShelfID for |contents|. If |contents| is not an app or is not | 173 // Returns ShelfID for |contents|. If |contents| is not an app or is not |
168 // pinned, returns the id of browser shrotcut. | 174 // pinned, returns the id of browser shrotcut. |
169 virtual ash::ShelfID GetShelfIDForWebContents( | 175 virtual ash::ShelfID GetShelfIDForWebContents( |
170 content::WebContents* contents) = 0; | 176 content::WebContents* contents) = 0; |
171 | 177 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 virtual bool ShelfBoundsChangesProbablyWithUser( | 243 virtual bool ShelfBoundsChangesProbablyWithUser( |
238 ash::WmShelf* shelf, | 244 ash::WmShelf* shelf, |
239 const AccountId& account_id) const = 0; | 245 const AccountId& account_id) const = 0; |
240 | 246 |
241 // Called when the user profile is fully loaded and ready to switch to. | 247 // Called when the user profile is fully loaded and ready to switch to. |
242 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0; | 248 virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0; |
243 | 249 |
244 // Controller to launch Arc apps in deferred mode. | 250 // Controller to launch Arc apps in deferred mode. |
245 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0; | 251 virtual ArcAppDeferredLauncherController* GetArcDeferredLauncher() = 0; |
246 | 252 |
253 AppIconLoader* GetAppIconLoaderForApp(const std::string& app_id); | |
254 | |
255 // Sets the shelf auto-hide and/or alignment behavior from prefs. | |
256 void SetShelfAutoHideBehaviorFromPrefs(); | |
257 void SetShelfAlignmentFromPrefs(); | |
258 void SetShelfBehaviorsFromPrefs(); | |
259 | |
260 // Sets LauncherControllerHelper or AppIconLoader for test, taking ownership. | |
261 void SetLauncherControllerHelperForTest( | |
262 std::unique_ptr<LauncherControllerHelper> helper); | |
263 void SetAppIconLoadersForTest( | |
264 std::vector<std::unique_ptr<AppIconLoader>>& loaders); | |
265 | |
266 void SetProfileForTest(Profile* profile); | |
267 | |
247 protected: | 268 protected: |
248 ChromeLauncherController(); | 269 ChromeLauncherController(); |
249 | 270 |
271 // Connects or reconnects to the mojom::ShelfController interface in ash. | |
272 // Returns true if connected and returns false in unit tests. | |
273 bool ConnectToShelfController(); | |
274 | |
275 // Accessor for subclasses to interact with the shelf controller. | |
276 ash::mojom::ShelfControllerPtr& shelf_controller() { | |
277 return shelf_controller_; | |
278 } | |
279 | |
280 // Attach to a specific profile. | |
281 virtual void AttachProfile(Profile* profile_to_attach); | |
282 | |
283 // ash::mojom::ShelfObserver: | |
284 void OnShelfCreated(int64_t display_id) override; | |
285 void OnAlignmentChanged(ash::ShelfAlignment alignment, | |
286 int64_t display_id) override; | |
287 void OnAutoHideBehaviorChanged(ash::ShelfAutoHideBehavior auto_hide, | |
288 int64_t display_id) override; | |
289 | |
250 private: | 290 private: |
291 // AppIconLoaderDelegate: | |
292 void OnAppImageUpdated(const std::string& app_id, | |
293 const gfx::ImageSkia& image) override; | |
294 | |
251 static ChromeLauncherController* instance_; | 295 static ChromeLauncherController* instance_; |
252 | 296 |
297 // The currently loaded profile used for prefs and loading extensions. This is | |
298 // NOT necessarily the profile new windows are created with. Note that in | |
299 // multi-profile use cases this might change over time. | |
300 Profile* profile_ = nullptr; | |
301 | |
302 // Ash's mojom::ShelfController used to change shelf state. | |
303 ash::mojom::ShelfControllerPtr shelf_controller_; | |
304 | |
305 // The binding this instance uses to implment mojom::ShelfObserver | |
306 mojo::AssociatedBinding<ash::mojom::ShelfObserver> observer_binding_; | |
307 | |
308 // Used to get app info for tabs. | |
309 std::unique_ptr<LauncherControllerHelper> launcher_controller_helper_; | |
310 | |
311 // An observer that manages the shelf title and icon for settings windows. | |
253 SettingsWindowObserver settings_window_observer_; | 312 SettingsWindowObserver settings_window_observer_; |
254 | 313 |
314 // Used to load the images for app items. | |
315 std::vector<std::unique_ptr<AppIconLoader>> app_icon_loaders_; | |
316 | |
255 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); | 317 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherController); |
256 }; | 318 }; |
257 | 319 |
258 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ | 320 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_CHROME_LAUNCHER_CONTROLLER_H_ |
OLD | NEW |