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