1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ASH_PUBLIC_CPP_WALLPAPER_CONTROLLER_H_
6 #define ASH_PUBLIC_CPP_WALLPAPER_CONTROLLER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "ash/public/cpp/ash_public_export.h"
12 #include "ash/public/cpp/wallpaper_info.h"
13 #include "ash/public/cpp/wallpaper_types.h"
14 #include "base/files/file_path.h"
15 #include "base/time/time.h"
16 
17 class AccountId;
18 
19 namespace gfx {
20 class ImageSkia;
21 }
22 
23 namespace ash {
24 
25 class WallpaperControllerObserver;
26 class WallpaperControllerClient;
27 
28 // Used by Chrome to set the wallpaper displayed by ash.
29 class ASH_PUBLIC_EXPORT WallpaperController {
30  public:
31   static WallpaperController* Get();
32 
33   // Sets the client interface, used to show the wallpaper picker, etc.
34   virtual void SetClient(WallpaperControllerClient* client) = 0;
35 
36   // Sets paths for wallpaper directories and the device policy wallpaper path.
37   // |user_data|: Directory where user data can be written.
38   // |wallpapers|: Directory where downloaded chromeos wallpapers reside.
39   // |custom_wallpapers|: Directory where custom wallpapers reside.
40   // |device_policy_wallpaper|: Path of the device policy wallpaper (if any).
41   virtual void Init(const base::FilePath& user_data,
42                     const base::FilePath& wallpapers,
43                     const base::FilePath& custom_wallpapers,
44                     const base::FilePath& device_policy_wallpaper) = 0;
45 
46   // Sets wallpaper from a local file and updates the saved wallpaper info for
47   // the user.
48   // |account_id|: The user's account id.
49   // |wallpaper_files_id|: The file id for |account_id|.
50   // |file_name|: The name of the wallpaper file.
51   // |layout|: The layout of the wallpaper, used for wallpaper resizing.
52   // |image|: The wallpaper image.
53   // |preview_mode|: If true, show the wallpaper immediately but doesn't change
54   //                 the user wallpaper info until |ConfirmPreviewWallpaper| is
55   //                 called.
56   virtual void SetCustomWallpaper(const AccountId& account_id,
57                                   const std::string& wallpaper_files_id,
58                                   const std::string& file_name,
59                                   WallpaperLayout layout,
60                                   const gfx::ImageSkia& image,
61                                   bool preview_mode) = 0;
62 
63   // Sets wallpaper from the Chrome OS wallpaper picker. If the wallpaper file
64   // corresponding to |url| already exists in local file system (i.e.
65   // |SetOnlineWallpaperFromData| was called earlier with the same |url|),
66   // returns true and sets wallpaper for the user, otherwise returns false.
67   // |account_id|: The user's account id.
68   // |url|: The wallpaper url.
69   // |layout|: The layout of the wallpaper, used for wallpaper resizing.
70   // |preview_mode|: If true, show the wallpaper immediately but doesn't change
71   //                 the user wallpaper info until |ConfirmPreviewWallpaper| is
72   //                 called.
73   // Responds with true if the wallpaper file exists in local file system.
74   using SetOnlineWallpaperIfExistsCallback = base::OnceCallback<void(bool)>;
75   virtual void SetOnlineWallpaperIfExists(
76       const AccountId& account_id,
77       const std::string& url,
78       WallpaperLayout layout,
79       bool preview_mode,
80       SetOnlineWallpaperIfExistsCallback callback) = 0;
81 
82   // Sets wallpaper from the Chrome OS wallpaper picker and saves the wallpaper
83   // to local file system. After this, |SetOnlineWallpaperIfExists| will return
84   // true for the same |url|, so that there's no need to provide |image_data|
85   // when the same wallpaper needs to be set again or for another user.
86   // |account_id|: The user's account id.
87   // |url|: The wallpaper url.
88   // |layout|: The layout of the wallpaper, used for wallpaper resizing.
89   // |preview_mode|: If true, show the wallpaper immediately but doesn't change
90   //                 the user wallpaper info until |ConfirmPreviewWallpaper| is
91   //                 called.
92   // Responds with true if the wallpaper is set successfully (i.e. no decoding
93   // error etc.).
94   using SetOnlineWallpaperFromDataCallback = base::OnceCallback<void(bool)>;
95   virtual void SetOnlineWallpaperFromData(
96       const AccountId& account_id,
97       const std::string& image_data,
98       const std::string& url,
99       WallpaperLayout layout,
100       bool preview_mode,
101       SetOnlineWallpaperFromDataCallback callback) = 0;
102 
103   // Sets the user's wallpaper to be the default wallpaper. Note: different user
104   // types may have different default wallpapers.
105   // |account_id|: The user's account id.
106   // |wallpaper_files_id|: The file id for |account_id|.
107   // |show_wallpaper|: If false, don't show the new wallpaper now but only
108   //                   update cache.
109   virtual void SetDefaultWallpaper(const AccountId& account_id,
110                                    const std::string& wallpaper_files_id,
111                                    bool show_wallpaper) = 0;
112 
113   // Sets the paths of the customized default wallpaper to be used wherever a
114   // default wallpaper is needed. If a default wallpaper is being shown, updates
115   // the screen to replace the old default wallpaper. Note: it doesn't change
116   // the default wallpaper for guest and child accounts.
117   // |customized_default_small_path|: The file path of the small-size customized
118   //                                  default wallpaper, if any.
119   // |customized_default_large_path|: The file path of the large-size customized
120   //                                  default wallpaper, if any.
121   virtual void SetCustomizedDefaultWallpaperPaths(
122       const base::FilePath& customized_default_small_path,
123       const base::FilePath& customized_default_large_path) = 0;
124 
125   // Sets wallpaper from policy. If the user has logged in, show the policy
126   // wallpaper immediately, otherwise, the policy wallpaper will be shown the
127   // next time |ShowUserWallpaper| is called. Note: it is different from device
128   // policy.
129   // |account_id|: The user's account id.
130   // |wallpaper_files_id|: The file id for |account_id|.
131   // |data|: The data used to decode the image.
132   virtual void SetPolicyWallpaper(const AccountId& account_id,
133                                   const std::string& wallpaper_files_id,
134                                   const std::string& data) = 0;
135 
136   // Sets the path of device policy wallpaper.
137   // |device_policy_wallpaper_path|: The file path of the device policy
138   //                                 wallpaper if it was set or empty value if
139   //                                 it was cleared.
140   virtual void SetDevicePolicyWallpaperPath(
141       const base::FilePath& device_policy_wallpaper_path) = 0;
142 
143   // Sets wallpaper from a third-party app (as opposed to the Chrome OS
144   // wallpaper picker).
145   // |account_id|: The user's account id.
146   // |wallpaper_files_id|: The file id for |account_id|.
147   // |file_name|: The name of the wallpaper file.
148   // |layout|: The layout of the wallpaper, used for wallpaper resizing.
149   // |image|: The wallpaper image.
150   // Returns if the wallpaper is allowed to be shown on screen. It's false if:
151   // 1) the user is not permitted to change wallpaper, or
152   // 2) updating the on-screen wallpaper is not allowed at the given moment.
153   virtual bool SetThirdPartyWallpaper(const AccountId& account_id,
154                                       const std::string& wallpaper_files_id,
155                                       const std::string& file_name,
156                                       WallpaperLayout layout,
157                                       const gfx::ImageSkia& image) = 0;
158 
159   // Confirms the wallpaper being previewed to be set as the actual user
160   // wallpaper. Must be called in preview mode.
161   virtual void ConfirmPreviewWallpaper() = 0;
162 
163   // Cancels the wallpaper preview and reverts to the user wallpaper. Must be
164   // called in preview mode.
165   virtual void CancelPreviewWallpaper() = 0;
166 
167   // Updates the layout for the user's custom wallpaper and reloads the
168   // wallpaper with the new layout.
169   // |account_id|: The user's account id.
170   // |layout|: The new layout of the wallpaper.
171   virtual void UpdateCustomWallpaperLayout(const AccountId& account_id,
172                                            WallpaperLayout layout) = 0;
173 
174   // Shows the user's wallpaper, which is determined in the following order:
175   // 1) Use device policy wallpaper if it exists AND we are at the login screen.
176   // 2) Use user policy wallpaper if it exists.
177   // 3) Use the wallpaper set by the user (either by |SetOnlineWallpaper| or
178   //    |SetCustomWallpaper|), if any.
179   // 4) Use the default wallpaper of this user.
180   virtual void ShowUserWallpaper(const AccountId& account_id) = 0;
181 
182   // Used by the gaia-signin UI. Signin wallpaper is considered either as the
183   // device policy wallpaper or the default wallpaper.
184   virtual void ShowSigninWallpaper() = 0;
185 
186   // Shows a one-shot wallpaper, which does not belong to any particular user
187   // and is not saved to file. Note: the wallpaper will never be dimmed or
188   // blurred because it's assumed that the caller wants to show the image as is
189   // when using this method.
190   virtual void ShowOneShotWallpaper(const gfx::ImageSkia& image) = 0;
191 
192   // Shows a wallpaper that stays on top of everything except for the power off
193   // animation. All other wallpaper requests are ignored when the always-on-top
194   // wallpaper is being shown.
195   // |image_path|: The file path to read the image data from.
196   virtual void ShowAlwaysOnTopWallpaper(const base::FilePath& image_path) = 0;
197 
198   // Removes the always-on-top wallpaper. The wallpaper will revert to the
199   // previous one, or a default one if there was none. No-op if the current
200   // wallpaper is not always-on-top.
201   virtual void RemoveAlwaysOnTopWallpaper() = 0;
202 
203   // Removes all of the user's saved wallpapers and related info.
204   // |account_id|: The user's account id.
205   // |wallpaper_files_id|: The file id for |account_id|.
206   virtual void RemoveUserWallpaper(const AccountId& account_id,
207                                    const std::string& wallpaper_files_id) = 0;
208 
209   // Removes all of the user's saved wallpapers and related info if the
210   // wallpaper was set by |SetPolicyWallpaper|. In addition, sets the user's
211   // wallpaper to be the default. If the user has logged in, show the default
212   // wallpaper immediately, otherwise, the default wallpaper will be shown the
213   // next time |ShowUserWallpaper| is called.
214   // |account_id|: The user's account id.
215   // |wallpaper_files_id|: The file id for |account_id|.
216   virtual void RemovePolicyWallpaper(const AccountId& account_id,
217                                      const std::string& wallpaper_files_id) = 0;
218 
219   // Returns the urls of the wallpapers that exist in local file system (i.e.
220   // |SetOnlineWallpaperFromData| was called earlier). The url is used as id
221   // to identify which wallpapers are available to be set offline.
222   using GetOfflineWallpaperListCallback =
223       base::OnceCallback<void(const std::vector<std::string>&)>;
224   virtual void GetOfflineWallpaperList(
225       GetOfflineWallpaperListCallback callback) = 0;
226 
227   // Sets wallpaper animation duration. Passing an empty value disables the
228   // animation.
229   virtual void SetAnimationDuration(base::TimeDelta animation_duration) = 0;
230 
231   // Opens the wallpaper picker if the active user is not controlled by policy
232   // and it's allowed to change wallpaper per the user type and the login state.
233   virtual void OpenWallpaperPickerIfAllowed() = 0;
234 
235   // Minimizes all windows except the active window.
236   // |user_id_hash|: The hash value corresponding to |User::username_hash|.
237   virtual void MinimizeInactiveWindows(const std::string& user_id_hash) = 0;
238 
239   // Restores all minimized windows to their previous states. This should only
240   // be called after calling |MinimizeInactiveWindows|.
241   // |user_id_hash|: The hash value corresponding to |User::username_hash|.
242   virtual void RestoreMinimizedWindows(const std::string& user_id_hash) = 0;
243 
244   // Add and remove wallpaper observers.
245   virtual void AddObserver(WallpaperControllerObserver* observer) = 0;
246   virtual void RemoveObserver(WallpaperControllerObserver* observer) = 0;
247 
248   // Returns the wallpaper image currently being shown.
249   virtual gfx::ImageSkia GetWallpaperImage() = 0;
250 
251   // Returns the wallpaper prominent colors.
252   virtual const std::vector<SkColor>& GetWallpaperColors() = 0;
253 
254   // Returns whether the current wallpaper is blurred on lock/login screen.
255   virtual bool IsWallpaperBlurredForLockState() const = 0;
256 
257   // Returns true if the wallpaper of the currently active user (if any) is
258   // controlled by policy (excluding device policy). If there's no active user,
259   // returns false.
260   virtual bool IsActiveUserWallpaperControlledByPolicy() = 0;
261 
262   // Returns a struct with info about the active user's wallpaper; the location
263   // is an empty string and the layout is invalid if there's no active user.
264   virtual WallpaperInfo GetActiveUserWallpaperInfo() = 0;
265 
266   // Returns true if the wallpaper setting (used to open the wallpaper picker)
267   // should be visible.
268   virtual bool ShouldShowWallpaperSetting() = 0;
269 
270  protected:
271   static WallpaperController* g_instance_;
272 };
273 
274 }  // namespace ash
275 
276 #endif  // ASH_PUBLIC_CPP_WALLPAPER_CONTROLLER_H_
277