Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / background / ash_user_wallpaper_delegate.cc
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.
4
5 #include "chrome/browser/chromeos/background/ash_user_wallpaper_delegate.h"
6
7 #include "ash/shell.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"
22
23 namespace chromeos {
24
25 namespace {
26
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)) {
33     return true;
34   }
35
36   return false;
37 }
38
39 class UserWallpaperDelegate : public ash::UserWallpaperDelegate {
40  public:
41   UserWallpaperDelegate()
42       : boot_animation_finished_(false),
43         animation_duration_override_in_ms_(0) {
44   }
45
46   virtual ~UserWallpaperDelegate() {
47   }
48
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);
53   }
54
55   virtual int GetAnimationDurationOverride() OVERRIDE {
56     return animation_duration_override_in_ms_;
57   }
58
59   virtual void SetAnimationDurationOverride(
60       int animation_duration_in_ms) OVERRIDE {
61     animation_duration_override_in_ms_ = animation_duration_in_ms;
62   }
63
64   virtual bool ShouldShowInitialAnimation() OVERRIDE {
65     if (IsNormalWallpaperChange() || boot_animation_finished_)
66       return false;
67
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)
75       return false;
76
77     return true;
78   }
79
80   virtual void UpdateWallpaper(bool clear_cache) OVERRIDE {
81     chromeos::WallpaperManager::Get()->UpdateWallpaper(clear_cache);
82   }
83
84   virtual void InitializeWallpaper() OVERRIDE {
85     chromeos::WallpaperManager::Get()->InitializeWallpaper();
86   }
87
88   virtual void OpenSetWallpaperPage() OVERRIDE {
89     if (CanOpenSetWallpaperPage())
90       wallpaper_manager_util::OpenWallpaperManager();
91   }
92
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())
98       return false;
99
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) {
106       return false;
107     }
108     const User* user = chromeos::UserManager::Get()->GetActiveUser();
109     if (!user)
110       return false;
111     if (chromeos::WallpaperManager::Get()->IsPolicyControlled(user->email()))
112       return false;
113     return true;
114   }
115
116   virtual void OnWallpaperAnimationFinished() OVERRIDE {
117     content::NotificationService::current()->Notify(
118         chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED,
119         content::NotificationService::AllSources(),
120         content::NotificationService::NoDetails());
121   }
122
123   virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
124     // Make sure that boot animation type is used only once.
125     boot_animation_finished_ = true;
126   }
127
128  private:
129   bool boot_animation_finished_;
130
131   // The animation duration to show a new wallpaper if an animation is required.
132   int animation_duration_override_in_ms_;
133
134   DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate);
135 };
136
137 }  // namespace
138
139 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() {
140   return new chromeos::UserWallpaperDelegate();
141 }
142
143 }  // namespace chromeos