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