1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WEBUI_SCREEN_LOCKER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WEBUI_SCREEN_LOCKER_H_ 7 8 #include <string> 9 10 #include "ash/shell_delegate.h" 11 #include "ash/wm/lock_state_observer.h" 12 #include "base/compiler_specific.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/weak_ptr.h" 15 #include "base/time/time.h" 16 #include "chrome/browser/chromeos/login/lock/screen_locker_delegate.h" 17 #include "chrome/browser/chromeos/login/signin_specifics.h" 18 #include "chrome/browser/chromeos/login/ui/lock_window.h" 19 #include "chrome/browser/chromeos/login/ui/login_display.h" 20 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" 21 #include "chromeos/dbus/power_manager_client.h" 22 #include "content/public/browser/notification_observer.h" 23 #include "content/public/browser/notification_registrar.h" 24 #include "ui/keyboard/keyboard_controller_observer.h" 25 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget_observer.h" 27 28 namespace content { 29 class WebUI; 30 } 31 32 namespace chromeos { 33 34 class OobeUI; 35 class ScreenLocker; 36 class WebUILoginDisplay; 37 38 namespace login { 39 class NetworkStateHelper; 40 } 41 42 namespace test { 43 class WebUIScreenLockerTester; 44 } 45 46 // This version of ScreenLockerDelegate displays a WebUI lock screen based on 47 // the Oobe account picker screen. 48 class WebUIScreenLocker : public WebUILoginView, 49 public LoginDisplay::Delegate, 50 public ScreenLockerDelegate, 51 public LockWindow::Observer, 52 public ash::LockStateObserver, 53 public views::WidgetObserver, 54 public PowerManagerClient::Observer, 55 public ash::VirtualKeyboardStateObserver, 56 public keyboard::KeyboardControllerObserver { 57 public: 58 explicit WebUIScreenLocker(ScreenLocker* screen_locker); 59 60 // ScreenLockerDelegate implementation. 61 virtual void LockScreen() OVERRIDE; 62 virtual void ScreenLockReady() OVERRIDE; 63 virtual void OnAuthenticate() OVERRIDE; 64 virtual void SetInputEnabled(bool enabled) OVERRIDE; 65 virtual void ShowErrorMessage( 66 int error_msg_id, 67 HelpAppLauncher::HelpTopic help_topic_id) OVERRIDE; 68 virtual void ClearErrors() OVERRIDE; 69 virtual void AnimateAuthenticationSuccess() OVERRIDE; 70 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; 71 virtual content::WebUI* GetAssociatedWebUI() OVERRIDE; 72 virtual void OnLockWebUIReady() OVERRIDE; 73 virtual void OnLockBackgroundDisplayed() OVERRIDE; 74 75 // LoginDisplay::Delegate: implementation 76 virtual void CancelPasswordChangedFlow() OVERRIDE; 77 virtual void CreateAccount() OVERRIDE; 78 virtual void CompleteLogin(const UserContext& user_context) OVERRIDE; 79 virtual base::string16 GetConnectedNetworkName() OVERRIDE; 80 virtual bool IsSigninInProgress() const OVERRIDE; 81 virtual void Login(const UserContext& user_context, 82 const SigninSpecifics& specifics) OVERRIDE; 83 virtual void MigrateUserData(const std::string& old_password) OVERRIDE; 84 virtual void OnSigninScreenReady() OVERRIDE; 85 virtual void OnStartEnterpriseEnrollment() OVERRIDE; 86 virtual void OnStartKioskEnableScreen() OVERRIDE; 87 virtual void OnStartKioskAutolaunchScreen() OVERRIDE; 88 virtual void ShowWrongHWIDScreen() OVERRIDE; 89 virtual void ResetPublicSessionAutoLoginTimer() OVERRIDE; 90 virtual void ResyncUserData() OVERRIDE; 91 virtual void SetDisplayEmail(const std::string& email) OVERRIDE; 92 virtual void Signout() OVERRIDE; 93 94 // content::NotificationObserver (via WebUILoginView) implementation. 95 virtual void Observe(int type, 96 const content::NotificationSource& source, 97 const content::NotificationDetails& details) OVERRIDE; 98 99 // LockWindow::Observer implementation. 100 virtual void OnLockWindowReady() OVERRIDE; 101 102 // LockStateObserver override. 103 virtual void OnLockStateEvent( 104 ash::LockStateObserver::EventType event) OVERRIDE; 105 106 // WidgetObserver override. 107 virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; 108 109 // PowerManagerClient::Observer overrides: 110 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE; 111 virtual void LidEventReceived(bool open, 112 const base::TimeTicks& time) OVERRIDE; 113 114 // Overridden from content::WebContentsObserver: 115 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; 116 117 // Overridden from ash::KeyboardStateObserver: 118 virtual void OnVirtualKeyboardStateChanged(bool activated) OVERRIDE; 119 120 // Overridden from keyboard::KeyboardControllerObserver: 121 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE; 122 123 // Returns instance of the OOBE WebUI. 124 OobeUI* GetOobeUI(); 125 126 private: 127 friend class test::WebUIScreenLockerTester; 128 129 virtual ~WebUIScreenLocker(); 130 131 // Ensures that user pod is focused. 132 void FocusUserPod(); 133 134 // The screen locker window. 135 views::Widget* lock_window_; 136 137 // Login UI implementation instance. 138 scoped_ptr<WebUILoginDisplay> login_display_; 139 140 // Used for user image changed notifications. 141 content::NotificationRegistrar registrar_; 142 143 // Tracks when the lock window is displayed and ready. 144 bool lock_ready_; 145 146 // Tracks when the WebUI finishes loading. 147 bool webui_ready_; 148 149 // Time when lock was initiated, required for metrics. 150 base::TimeTicks lock_time_; 151 152 scoped_ptr<login::NetworkStateHelper> network_state_helper_; 153 154 // True is subscribed as keyboard controller observer. 155 bool is_observing_keyboard_; 156 157 // The bounds of the virtual keyboard. 158 gfx::Rect keyboard_bounds_; 159 160 base::WeakPtrFactory<WebUIScreenLocker> weak_factory_; 161 162 DISALLOW_COPY_AND_ASSIGN(WebUIScreenLocker); 163 }; 164 165 } // namespace chromeos 166 167 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOCK_WEBUI_SCREEN_LOCKER_H_ 168