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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
8 #include "ash/desktop_background/user_wallpaper_delegate.h"
9 #include "ash/wm/window_animations.h"
10 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/extensions/wallpaper_manager_util.h"
14 #include "chrome/browser/chromeos/login/startup_utils.h"
15 #include "chrome/browser/chromeos/login/user.h"
16 #include "chrome/browser/chromeos/login/user_manager.h"
17 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
18 #include "chrome/browser/chromeos/login/wizard_controller.h"
19 #include "chromeos/chromeos_switches.h"
20 #include "chromeos/login/login_state.h"
21 #include "content/public/browser/notification_service.h"
27 bool IsNormalWallpaperChange() {
28 if (chromeos::LoginState::Get()->IsUserLoggedIn() ||
29 !CommandLine::ForCurrentProcess()->HasSwitch(
30 switches::kFirstExecAfterBoot) ||
31 WizardController::IsZeroDelayEnabled() ||
32 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager)) {
39 class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
41 UserWallpaperDelegate()
42 : boot_animation_finished_(false),
43 animation_duration_override_in_ms_(0) {
46 virtual ~UserWallpaperDelegate() {
49 virtual int GetAnimationType() OVERRIDE {
50 return ShouldShowInitialAnimation() ?
51 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE :
52 static_cast<int>(wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
55 virtual int GetAnimationDurationOverride() OVERRIDE {
56 return animation_duration_override_in_ms_;
59 virtual void SetAnimationDurationOverride(
60 int animation_duration_in_ms) OVERRIDE {
61 animation_duration_override_in_ms_ = animation_duration_in_ms;
64 virtual bool ShouldShowInitialAnimation() OVERRIDE {
65 if (IsNormalWallpaperChange() || boot_animation_finished_)
68 // It is a first boot case now. If kDisableBootAnimation flag
69 // is passed, it only disables any transition after OOBE.
70 bool is_registered = StartupUtils::IsDeviceRegistered();
71 const CommandLine* command_line = CommandLine::ForCurrentProcess();
72 bool disable_boot_animation = command_line->
73 HasSwitch(switches::kDisableBootAnimation);
74 if (is_registered && disable_boot_animation)
80 virtual void UpdateWallpaper(bool clear_cache) OVERRIDE {
81 chromeos::WallpaperManager::Get()->UpdateWallpaper(clear_cache);
84 virtual void InitializeWallpaper() OVERRIDE {
85 chromeos::WallpaperManager::Get()->InitializeWallpaper();
88 virtual void OpenSetWallpaperPage() OVERRIDE {
89 if (CanOpenSetWallpaperPage())
90 wallpaper_manager_util::OpenWallpaperManager();
93 virtual bool CanOpenSetWallpaperPage() OVERRIDE {
94 const LoginState* login_state = LoginState::Get();
95 const LoginState::LoggedInUserType user_type =
96 login_state->GetLoggedInUserType();
97 if (!login_state->IsUserLoggedIn())
100 // Whitelist user types that are allowed to change their wallpaper. (Guest
101 // users are not, see crosbug 26900.)
102 if (user_type != LoginState::LOGGED_IN_USER_REGULAR &&
103 user_type != LoginState::LOGGED_IN_USER_OWNER &&
104 user_type != LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT &&
105 user_type != LoginState::LOGGED_IN_USER_LOCALLY_MANAGED) {
108 const User* user = chromeos::UserManager::Get()->GetActiveUser();
111 if (chromeos::WallpaperManager::Get()->IsPolicyControlled(user->email()))
116 virtual void OnWallpaperAnimationFinished() OVERRIDE {
117 content::NotificationService::current()->Notify(
118 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
119 content::NotificationService::AllSources(),
120 content::NotificationService::NoDetails());
123 virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
124 // Make sure that boot animation type is used only once.
125 boot_animation_finished_ = true;
129 bool boot_animation_finished_;
131 // The animation duration to show a new wallpaper if an animation is required.
132 int animation_duration_override_in_ms_;
134 DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
139 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
140 return new chromeos::UserWallpaperDelegate();
143 } // namespace chromeos