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/wallpaper_manager.h" 16 #include "chrome/browser/chromeos/login/wizard_controller.h" 17 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/chrome_pages.h" 21 #include "chromeos/chromeos_switches.h" 22 #include "chromeos/login/login_state.h" 23 #include "content/public/browser/notification_service.h" 24 25 namespace chromeos { 26 27 namespace { 28 29 bool IsNormalWallpaperChange() { 30 if (chromeos::LoginState::Get()->IsUserLoggedIn() || 31 !CommandLine::ForCurrentProcess()->HasSwitch( 32 switches::kFirstExecAfterBoot) || 33 WizardController::IsZeroDelayEnabled() || 34 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginManager)) { 35 return true; 36 } 37 38 return false; 39 } 40 41 class UserWallpaperDelegate : public ash::UserWallpaperDelegate { 42 public: 43 UserWallpaperDelegate() : boot_animation_finished_(false) { 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>(views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 53 } 54 55 virtual bool ShouldShowInitialAnimation() OVERRIDE { 56 if (IsNormalWallpaperChange() || boot_animation_finished_) 57 return false; 58 59 // It is a first boot case now. If kDisableBootAnimation flag 60 // is passed, it only disables any transition after OOBE. 61 // |kDisableOobeAnimation| disables OOBE animation for slow hardware. 62 bool is_registered = StartupUtils::IsDeviceRegistered(); 63 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 64 bool disable_boot_animation = command_line-> 65 HasSwitch(switches::kDisableBootAnimation); 66 bool disable_oobe_animation = command_line-> 67 HasSwitch(switches::kDisableOobeAnimation); 68 if ((!is_registered && disable_oobe_animation) || 69 (is_registered && disable_boot_animation)) 70 return false; 71 72 return true; 73 } 74 75 virtual void UpdateWallpaper() OVERRIDE { 76 chromeos::WallpaperManager::Get()->UpdateWallpaper(); 77 } 78 79 virtual void InitializeWallpaper() OVERRIDE { 80 chromeos::WallpaperManager::Get()->InitializeWallpaper(); 81 } 82 83 virtual void OpenSetWallpaperPage() OVERRIDE { 84 wallpaper_manager_util::OpenWallpaperManager(); 85 } 86 87 virtual bool CanOpenSetWallpaperPage() OVERRIDE { 88 return LoginState::Get()->IsUserAuthenticated(); 89 } 90 91 virtual void OnWallpaperAnimationFinished() OVERRIDE { 92 content::NotificationService::current()->Notify( 93 chrome::NOTIFICATION_WALLPAPER_ANIMATION_FINISHED, 94 content::NotificationService::AllSources(), 95 content::NotificationService::NoDetails()); 96 } 97 98 virtual void OnWallpaperBootAnimationFinished() OVERRIDE { 99 // Make sure that boot animation type is used only once. 100 boot_animation_finished_ = true; 101 } 102 103 private: 104 bool boot_animation_finished_; 105 106 DISALLOW_COPY_AND_ASSIGN(UserWallpaperDelegate); 107 }; 108 109 } // namespace 110 111 ash::UserWallpaperDelegate* CreateUserWallpaperDelegate() { 112 return new chromeos::UserWallpaperDelegate(); 113 } 114 115 } // namespace chromeos 116