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 #include <vector>
     10 
     11 #include "base/compiler_specific.h"
     12 #include "base/memory/scoped_ptr.h"
     13 #include "base/memory/weak_ptr.h"
     14 #include "chrome/browser/chromeos/login/app_launch_controller.h"
     15 #include "chrome/browser/chromeos/login/auth_prewarmer.h"
     16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
     17 #include "chrome/browser/chromeos/login/login_display.h"
     18 #include "chrome/browser/chromeos/login/login_display_host.h"
     19 #include "chrome/browser/chromeos/login/wizard_controller.h"
     20 #include "chrome/browser/chromeos/settings/device_settings_service.h"
     21 #include "chromeos/audio/cras_audio_handler.h"
     22 #include "chromeos/dbus/session_manager_client.h"
     23 #include "content/public/browser/notification_observer.h"
     24 #include "content/public/browser/notification_registrar.h"
     25 #include "content/public/browser/web_contents_observer.h"
     26 #include "ui/gfx/rect.h"
     27 
     28 class PrefService;
     29 
     30 namespace policy {
     31 class AutoEnrollmentClient;
     32 }  // namespace policy
     33 
     34 namespace chromeos {
     35 
     36 class FocusRingController;
     37 class KeyboardDrivenOobeKeyHandler;
     38 class OobeUI;
     39 class WebUILoginDisplay;
     40 class WebUILoginView;
     41 
     42 // An implementation class for OOBE/login WebUI screen host.
     43 // It encapsulates controllers, background integration and flow.
     44 class LoginDisplayHostImpl : public LoginDisplayHost,
     45                              public content::NotificationObserver,
     46                              public content::WebContentsObserver,
     47                              public chromeos::SessionManagerClient::Observer,
     48                              public chromeos::CrasAudioHandler::AudioObserver {
     49  public:
     50   explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds);
     51   virtual ~LoginDisplayHostImpl();
     52 
     53   // Returns the default LoginDispalyHost instance if it has been created.
     54   static LoginDisplayHost* default_host() {
     55     return default_host_;
     56   }
     57 
     58   // LoginDisplayHost implementation:
     59   virtual LoginDisplay* CreateLoginDisplay(
     60       LoginDisplay::Delegate* delegate) OVERRIDE;
     61   virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
     62   virtual WebUILoginView* GetWebUILoginView() const OVERRIDE;
     63   virtual void BeforeSessionStart() OVERRIDE;
     64   virtual void Finalize() OVERRIDE;
     65   virtual void OnCompleteLogin() OVERRIDE;
     66   virtual void OpenProxySettings() OVERRIDE;
     67   virtual void SetStatusAreaVisible(bool visible) OVERRIDE;
     68   virtual void CheckForAutoEnrollment() OVERRIDE;
     69   virtual void GetAutoEnrollmentCheckResult(
     70       const GetAutoEnrollmentCheckResultCallback& callback) OVERRIDE;
     71   virtual void StartWizard(
     72       const std::string& first_screen_name,
     73       scoped_ptr<DictionaryValue> screen_parameters) OVERRIDE;
     74   virtual WizardController* GetWizardController() OVERRIDE;
     75   virtual AppLaunchController* GetAppLaunchController() OVERRIDE;
     76   virtual void StartUserAdding(
     77       const base::Closure& completion_callback) OVERRIDE;
     78   virtual void StartSignInScreen(const LoginScreenContext& context) OVERRIDE;
     79   virtual void ResumeSignInScreen() OVERRIDE;
     80   virtual void OnPreferencesChanged() OVERRIDE;
     81   virtual void PrewarmAuthentication() OVERRIDE;
     82   virtual void StartAppLaunch(const std::string& app_id) OVERRIDE;
     83 
     84   // Creates WizardController instance.
     85   WizardController* CreateWizardController();
     86 
     87   // Called when the first browser window is created, but before it's shown.
     88   void OnBrowserCreated();
     89 
     90   // Returns instance of the OOBE WebUI.
     91   OobeUI* GetOobeUI() const;
     92 
     93   const gfx::Rect& background_bounds() const { return background_bounds_; }
     94 
     95   // Trace id for ShowLoginWebUI event (since there exists at most one login
     96   // WebUI at a time).
     97   static const int kShowLoginWebUIid;
     98 
     99   views::Widget* login_window_for_test() { return login_window_; }
    100 
    101  protected:
    102   // content::NotificationObserver implementation:
    103   virtual void Observe(int type,
    104                        const content::NotificationSource& source,
    105                        const content::NotificationDetails& details) OVERRIDE;
    106 
    107   // Overridden from content::WebContentsObserver:
    108   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
    109 
    110   // Overridden from chromeos::SessionManagerClient::Observer:
    111   virtual void EmitLoginPromptVisibleCalled() OVERRIDE;
    112 
    113   // Overridden from chromeos::CrasAudioHandler::AudioObserver:
    114   virtual void OnActiveOutputNodeChanged() OVERRIDE;
    115 
    116  private:
    117   // Way to restore if renderer have crashed.
    118   enum RestorePath {
    119     RESTORE_UNKNOWN,
    120     RESTORE_WIZARD,
    121     RESTORE_SIGN_IN,
    122     RESTORE_ADD_USER_INTO_SESSION,
    123   };
    124 
    125   // Type of animations to run after the login screen.
    126   enum FinalizeAnimationType {
    127     ANIMATION_NONE,       // No animation.
    128     ANIMATION_WORKSPACE,  // Use initial workspace animation (drop and
    129                           // and fade in workspace). Used for user login.
    130     ANIMATION_FADE_OUT,   // Fade out login screen. Used for app launch.
    131   };
    132 
    133   // Marks display host for deletion.
    134   // If |post_quit_task| is true also posts Quit task to the MessageLoop.
    135   void ShutdownDisplayHost(bool post_quit_task);
    136 
    137   // Schedules workspace transition animation.
    138   void ScheduleWorkspaceAnimation();
    139 
    140   // Schedules fade out animation.
    141   void ScheduleFadeOutAnimation();
    142 
    143   // Callback for the ownership status check.
    144   void OnOwnershipStatusCheckDone(
    145       DeviceSettingsService::OwnershipStatus status);
    146 
    147   // Callback for completion of the |auto_enrollment_client_|.
    148   void OnAutoEnrollmentClientDone();
    149 
    150   // Forces auto-enrollment on the appropriate controller.
    151   void ForceAutoEnrollment();
    152 
    153   // Loads given URL. Creates WebUILoginView if needed.
    154   void LoadURL(const GURL& url);
    155 
    156   // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
    157   void ShowWebUI();
    158 
    159   // Starts postponed WebUI (OOBE/sign in) if it was waiting for
    160   // wallpaper animation end.
    161   void StartPostponedWebUI();
    162 
    163   // Initializes |login_window_| and |login_view_| fields if needed.
    164   void InitLoginWindowAndView();
    165 
    166   // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
    167   void ResetLoginWindowAndView();
    168 
    169   // Deletes |auth_prewarmer_|.
    170   void OnAuthPrewarmDone();
    171 
    172   // Toggles OOBE progress bar visibility, the bar is hidden by default.
    173   void SetOobeProgressBarVisible(bool visible);
    174 
    175   // Notifies the interested parties of the auto enrollment check result.
    176   void NotifyAutoEnrollmentCheckResult(bool should_auto_enroll);
    177 
    178   // Tries to play startup sound. If sound can't be played right now,
    179   // for instance, because cras server is not initialized, playback
    180   // will be delayed.
    181   void TryToPlayStartupSound();
    182 
    183   // Called when login-prompt-visible signal is caught.
    184   void OnLoginPromptVisible();
    185 
    186   // Used to calculate position of the screens and background.
    187   gfx::Rect background_bounds_;
    188 
    189   content::NotificationRegistrar registrar_;
    190 
    191   base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_;
    192 
    193   // Default LoginDisplayHost.
    194   static LoginDisplayHost* default_host_;
    195 
    196   // Sign in screen controller.
    197   scoped_ptr<ExistingUserController> sign_in_controller_;
    198 
    199   // OOBE and some screens (camera, recovery) controller.
    200   scoped_ptr<WizardController> wizard_controller_;
    201 
    202   // App launch controller.
    203   scoped_ptr<AppLaunchController> app_launch_controller_;
    204 
    205   // Client for enterprise auto-enrollment check.
    206   scoped_ptr<policy::AutoEnrollmentClient> auto_enrollment_client_;
    207 
    208   // Has ShutdownDisplayHost() already been called?  Used to avoid posting our
    209   // own deletion to the message loop twice if the user logs out while we're
    210   // still in the process of cleaning up after login (http://crbug.com/134463).
    211   bool shutting_down_;
    212 
    213   // Whether progress bar is shown on the OOBE page.
    214   bool oobe_progress_bar_visible_;
    215 
    216   // True if session start is in progress.
    217   bool session_starting_;
    218 
    219   // Container of the screen we are displaying.
    220   views::Widget* login_window_;
    221 
    222   // Container of the view we are displaying.
    223   WebUILoginView* login_view_;
    224 
    225   // Login display we are using.
    226   WebUILoginDisplay* webui_login_display_;
    227 
    228   // True if the login display is the current screen.
    229   bool is_showing_login_;
    230 
    231   // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
    232   // received.
    233   bool is_wallpaper_loaded_;
    234 
    235   // Stores status area current visibility to be applied once login WebUI
    236   // is shown.
    237   bool status_area_saved_visibility_;
    238 
    239   // If true, WebUI is initialized in a hidden state and shown after the
    240   // wallpaper animation is finished (when it is enabled) or the user pods have
    241   // been loaded (otherwise).
    242   // By default is true. Could be used to tune performance if needed.
    243   bool initialize_webui_hidden_;
    244 
    245   // True if WebUI is initialized in hidden state and we're waiting for
    246   // wallpaper load animation to finish.
    247   bool waiting_for_wallpaper_load_;
    248 
    249   // True if WebUI is initialized in hidden state and we're waiting for user
    250   // pods to load.
    251   bool waiting_for_user_pods_;
    252 
    253   // How many times renderer has crashed.
    254   int crash_count_;
    255 
    256   // Way to restore if renderer have crashed.
    257   RestorePath restore_path_;
    258 
    259   // Stored parameters for StartWizard, required to restore in case of crash.
    260   std::string wizard_first_screen_name_;
    261   scoped_ptr<DictionaryValue> wizard_screen_parameters_;
    262 
    263   // Old value of the ash::internal::kIgnoreSoloWindowFramePainterPolicy
    264   // property of the root window for |login_window_|.
    265   bool old_ignore_solo_window_frame_painter_policy_value_;
    266 
    267   // Called before host deletion.
    268   base::Closure completion_callback_;
    269 
    270   // Active instance of authentication prewarmer.
    271   scoped_ptr<AuthPrewarmer> auth_prewarmer_;
    272 
    273   // A focus ring controller to draw focus ring around view for keyboard
    274   // driven oobe.
    275   scoped_ptr<FocusRingController> focus_ring_controller_;
    276 
    277   // Handles special keys for keyboard driven oobe.
    278   scoped_ptr<KeyboardDrivenOobeKeyHandler> keyboard_driven_oobe_key_handler_;
    279 
    280   // Whether auto enrollment client has done the check.
    281   bool auto_enrollment_check_done_;
    282 
    283   // Callbacks to notify when auto enrollment client has done the check.
    284   std::vector<GetAutoEnrollmentCheckResultCallback>
    285       get_auto_enrollment_result_callbacks_;
    286 
    287   FinalizeAnimationType finalize_animation_type_;
    288 
    289   base::WeakPtrFactory<LoginDisplayHostImpl> animation_weak_ptr_factory_;
    290 
    291   // Time when login prompt visible signal is received. Used for
    292   // calculations of delay before startup sound.
    293   base::TimeTicks login_prompt_visible_time_;
    294 
    295   // True when request to play startup sound was sent to
    296   // SoundsManager.
    297   bool startup_sound_played_;
    298 
    299   // When true, startup sound should be played only when spoken
    300   // feedback is enabled.  Otherwise, startup sound should be played
    301   // in any case.
    302   bool startup_sound_honors_spoken_feedback_;
    303 
    304   DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl);
    305 };
    306 
    307 }  // namespace chromeos
    308 
    309 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_
    310