Home | History | Annotate | Download | only in login
      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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_SCREEN_LOCKER_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_SCREEN_LOCKER_H_
      7 
      8 #include <string>
      9 
     10 #include "ash/wm/lock_state_observer.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/memory/weak_ptr.h"
     14 #include "base/time/time.h"
     15 #include "chrome/browser/chromeos/login/lock_window.h"
     16 #include "chrome/browser/chromeos/login/login_display.h"
     17 #include "chrome/browser/chromeos/login/screen_locker_delegate.h"
     18 #include "chrome/browser/chromeos/login/webui_login_view.h"
     19 #include "chromeos/dbus/power_manager_client.h"
     20 #include "content/public/browser/notification_observer.h"
     21 #include "content/public/browser/notification_registrar.h"
     22 #include "ui/views/widget/widget.h"
     23 #include "ui/views/widget/widget_observer.h"
     24 
     25 namespace content {
     26 class WebUI;
     27 }
     28 
     29 namespace chromeos {
     30 
     31 class ScreenLocker;
     32 class WebUILoginDisplay;
     33 struct UserContext;
     34 
     35 namespace login {
     36 class NetworkStateHelper;
     37 }
     38 
     39 namespace test {
     40 class WebUIScreenLockerTester;
     41 }
     42 
     43 // This version of ScreenLockerDelegate displays a WebUI lock screen based on
     44 // the Oobe account picker screen.
     45 class WebUIScreenLocker : public WebUILoginView,
     46                           public LoginDisplay::Delegate,
     47                           public ScreenLockerDelegate,
     48                           public LockWindow::Observer,
     49                           public ash::LockStateObserver,
     50                           public views::WidgetObserver,
     51                           public PowerManagerClient::Observer {
     52  public:
     53   explicit WebUIScreenLocker(ScreenLocker* screen_locker);
     54 
     55   // ScreenLockerDelegate implementation.
     56   virtual void LockScreen() OVERRIDE;
     57   virtual void ScreenLockReady() OVERRIDE;
     58   virtual void OnAuthenticate() OVERRIDE;
     59   virtual void SetInputEnabled(bool enabled) OVERRIDE;
     60   virtual void ShowBannerMessage(const std::string& message) OVERRIDE;
     61   virtual void ShowUserPodButton(const std::string& username,
     62                                  const std::string& iconURL,
     63                                  const base::Closure& click_callback) 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 OnStartDeviceReset() OVERRIDE;
     90   virtual void OnStartKioskAutolaunchScreen() OVERRIDE;
     91   virtual void ShowWrongHWIDScreen() OVERRIDE;
     92   virtual void ResetPublicSessionAutoLoginTimer() OVERRIDE;
     93   virtual void ResyncUserData() OVERRIDE;
     94   virtual void SetDisplayEmail(const std::string& email) OVERRIDE;
     95   virtual void Signout() OVERRIDE;
     96   virtual void LoginAsKioskApp(const std::string& app_id) 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 SystemResumed(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  private:
    122   friend class test::WebUIScreenLockerTester;
    123 
    124   virtual ~WebUIScreenLocker();
    125 
    126   // Ensures that user pod is focused.
    127   void FocusUserPod();
    128 
    129   // The screen locker window.
    130   views::Widget* lock_window_;
    131 
    132   // Login UI implementation instance.
    133   scoped_ptr<WebUILoginDisplay> login_display_;
    134 
    135   // Used for user image changed notifications.
    136   content::NotificationRegistrar registrar_;
    137 
    138   // Tracks when the lock window is displayed and ready.
    139   bool lock_ready_;
    140 
    141   // Tracks when the WebUI finishes loading.
    142   bool webui_ready_;
    143 
    144   // Time when lock was initiated, required for metrics.
    145   base::TimeTicks lock_time_;
    146 
    147   scoped_ptr<login::NetworkStateHelper> network_state_helper_;
    148 
    149   base::WeakPtrFactory<WebUIScreenLocker> weak_factory_;
    150 
    151   DISALLOW_COPY_AND_ASSIGN(WebUIScreenLocker);
    152 };
    153 
    154 }  // namespace chromeos
    155 
    156 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_WEBUI_SCREEN_LOCKER_H_
    157