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_LOGIN_DISPLAY_HOST_IMPL_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "chrome/browser/chromeos/login/auth_prewarmer.h"
     14 #include "chrome/browser/chromeos/login/existing_user_controller.h"
     15 #include "chrome/browser/chromeos/login/login_display.h"
     16 #include "chrome/browser/chromeos/login/login_display_host.h"
     17 #include "chrome/browser/chromeos/login/wizard_controller.h"
     18 #include "chrome/browser/chromeos/settings/device_settings_service.h"
     19 #include "content/public/browser/notification_observer.h"
     20 #include "content/public/browser/notification_registrar.h"
     21 #include "content/public/browser/web_contents_observer.h"
     22 #include "ui/gfx/rect.h"
     23 
     24 class PrefService;
     25 
     26 namespace policy {
     27 class AutoEnrollmentClient;
     28 }  // namespace policy
     29 
     30 namespace chromeos {
     31 
     32 class FocusRingController;
     33 class OobeUI;
     34 class WebUILoginDisplay;
     35 class WebUILoginView;
     36 
     37 // An implementation class for OOBE/login WebUI screen host.
     38 // It encapsulates controllers, background integration and flow.
     39 class LoginDisplayHostImpl : public LoginDisplayHost,
     40                              public content::NotificationObserver,
     41                              public content::WebContentsObserver {
     42  public:
     43   explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds);
     44   virtual ~LoginDisplayHostImpl();
     45 
     46   // Returns the default LoginDispalyHost instance if it has been created.
     47   static LoginDisplayHost* default_host() {
     48     return default_host_;
     49   }
     50 
     51   // LoginDisplayHost implementation:
     52   virtual LoginDisplay* CreateLoginDisplay(
     53       LoginDisplay::Delegate* delegate) OVERRIDE;
     54   virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
     55   virtual WebUILoginView* GetWebUILoginView() const OVERRIDE;
     56   virtual views::Widget* GetWidget() const OVERRIDE;
     57   virtual void BeforeSessionStart() OVERRIDE;
     58   virtual void Finalize() OVERRIDE;
     59   virtual void OnCompleteLogin() OVERRIDE;
     60   virtual void OpenProxySettings() OVERRIDE;
     61   virtual void SetOobeProgressBarVisible(bool visible) OVERRIDE;
     62   virtual void SetShutdownButtonEnabled(bool enable) OVERRIDE;
     63   virtual void SetStatusAreaVisible(bool visible) OVERRIDE;
     64   virtual void CheckForAutoEnrollment() OVERRIDE;
     65   virtual void StartWizard(
     66       const std::string& first_screen_name,
     67       scoped_ptr<DictionaryValue> screen_parameters) OVERRIDE;
     68   virtual WizardController* GetWizardController() OVERRIDE;
     69   virtual void StartUserAdding(
     70       const base::Closure& completion_callback) OVERRIDE;
     71   virtual void StartSignInScreen() OVERRIDE;
     72   virtual void ResumeSignInScreen() OVERRIDE;
     73   virtual void OnPreferencesChanged() OVERRIDE;
     74   virtual void PrewarmAuthentication() OVERRIDE;
     75 
     76   // Creates WizardController instance.
     77   WizardController* CreateWizardController();
     78 
     79   // Called when the first browser window is created, but before it's shown.
     80   void OnBrowserCreated();
     81 
     82   // Returns instance of the OOBE WebUI.
     83   OobeUI* GetOobeUI() const;
     84 
     85   const gfx::Rect& background_bounds() const { return background_bounds_; }
     86 
     87   // Trace id for ShowLoginWebUI event (since there exists at most one login
     88   // WebUI at a time).
     89   static const int kShowLoginWebUIid;
     90 
     91  protected:
     92   // content::NotificationObserver implementation:
     93   virtual void Observe(int type,
     94                        const content::NotificationSource& source,
     95                        const content::NotificationDetails& details) OVERRIDE;
     96 
     97   // Overridden from content::WebContentsObserver:
     98   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
     99 
    100  private:
    101   // Marks display host for deletion.
    102   // If |post_quit_task| is true also posts Quit task to the MessageLoop.
    103   void ShutdownDisplayHost(bool post_quit_task);
    104 
    105   // Start sign in transition animation.
    106   void StartAnimation();
    107 
    108   // Callback for the ownership status check.
    109   void OnOwnershipStatusCheckDone(DeviceSettingsService::OwnershipStatus status,
    110                                   bool current_user_is_owner);
    111 
    112   // Callback for completion of the |auto_enrollment_client_|.
    113   void OnAutoEnrollmentClientDone();
    114 
    115   // Forces auto-enrollment on the appropriate controller.
    116   void ForceAutoEnrollment();
    117 
    118   // Loads given URL. Creates WebUILoginView if needed.
    119   void LoadURL(const GURL& url);
    120 
    121   // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
    122   void ShowWebUI();
    123 
    124   // Starts postponed WebUI (OOBE/sign in) if it was waiting for
    125   // wallpaper animation end.
    126   void StartPostponedWebUI();
    127 
    128   // Initializes |login_window_| and |login_view_| fields if needed.
    129   void InitLoginWindowAndView();
    130 
    131   // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
    132   void ResetLoginWindowAndView();
    133 
    134   // Returns true if hosr running UI for adding users into session.
    135   bool IsRunningUserAdding();
    136 
    137   // Deletes |auth_prewarmer_|.
    138   void OnAuthPrewarmDone();
    139 
    140   // Used to calculate position of the screens and background.
    141   gfx::Rect background_bounds_;
    142 
    143   content::NotificationRegistrar registrar_;
    144 
    145   base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_;
    146 
    147   // Default LoginDisplayHost.
    148   static LoginDisplayHost* default_host_;
    149 
    150   // Sign in screen controller.
    151   scoped_ptr<ExistingUserController> sign_in_controller_;
    152 
    153   // OOBE and some screens (camera, recovery) controller.
    154   scoped_ptr<WizardController> wizard_controller_;
    155 
    156   // Client for enterprise auto-enrollment check.
    157   scoped_ptr<policy::AutoEnrollmentClient> auto_enrollment_client_;
    158 
    159   // Has ShutdownDisplayHost() already been called?  Used to avoid posting our
    160   // own deletion to the message loop twice if the user logs out while we're
    161   // still in the process of cleaning up after login (http://crbug.com/134463).
    162   bool shutting_down_;
    163 
    164   // Whether progress bar is shown on the OOBE page.
    165   bool oobe_progress_bar_visible_;
    166 
    167   // True if session start is in progress.
    168   bool session_starting_;
    169 
    170   // Container of the screen we are displaying.
    171   views::Widget* login_window_;
    172 
    173   // Container of the view we are displaying.
    174   WebUILoginView* login_view_;
    175 
    176   // Login display we are using.
    177   WebUILoginDisplay* webui_login_display_;
    178 
    179   // True if the login display is the current screen.
    180   bool is_showing_login_;
    181 
    182   // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
    183   // received.
    184   bool is_wallpaper_loaded_;
    185 
    186   // Stores status area current visibility to be applied once login WebUI
    187   // is shown.
    188   bool status_area_saved_visibility_;
    189 
    190   // If true, WebUI is initialized in a hidden state and shown after the
    191   // wallpaper animation is finished (when it is enabled) or the user pods have
    192   // been loaded (otherwise).
    193   // By default is true. Could be used to tune performance if needed.
    194   bool initialize_webui_hidden_;
    195 
    196   // True if WebUI is initialized in hidden state and we're waiting for
    197   // wallpaper load animation to finish.
    198   bool waiting_for_wallpaper_load_;
    199 
    200   // True if WebUI is initialized in hidden state and we're waiting for user
    201   // pods to load.
    202   bool waiting_for_user_pods_;
    203 
    204   // How many times renderer has crashed.
    205   int crash_count_;
    206 
    207   // Way to restore if renderer have crashed.
    208   enum {
    209     RESTORE_UNKNOWN,
    210     RESTORE_WIZARD,
    211     RESTORE_SIGN_IN,
    212     RESTORE_ADD_USER_INTO_SESSION,
    213   } restore_path_;
    214 
    215   // Stored parameters for StartWizard, required to restore in case of crash.
    216   std::string wizard_first_screen_name_;
    217   scoped_ptr<DictionaryValue> wizard_screen_parameters_;
    218 
    219   // Old value of the ash::internal::kIgnoreSoloWindowFramePainterPolicy
    220   // property of the root window for |login_window_|.
    221   bool old_ignore_solo_window_frame_painter_policy_value_;
    222 
    223   // Called before host deletion.
    224   base::Closure completion_callback_;
    225 
    226   // Active instance of authentication prewarmer.
    227   scoped_ptr<AuthPrewarmer> auth_prewarmer_;
    228 
    229   // A focus ring controller to draw focus ring around view for keyboard
    230   // driven oobe.
    231   scoped_ptr<FocusRingController> focus_ring_controller_;
    232 
    233   DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl);
    234 };
    235 
    236 }  // namespace chromeos
    237 
    238 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_
    239