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