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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_
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"
32 class AutoEnrollmentClient;
37 class FocusRingController;
38 class KeyboardDrivenOobeKeyHandler;
40 class WebUILoginDisplay;
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 {
51 explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds);
52 virtual ~LoginDisplayHostImpl();
54 // Returns the default LoginDispalyHost instance if it has been created.
55 static LoginDisplayHost* default_host() {
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;
87 // Creates WizardController instance.
88 WizardController* CreateWizardController();
90 // Called when the first browser window is created, but before it's shown.
91 void OnBrowserCreated();
93 // Returns instance of the OOBE WebUI.
94 OobeUI* GetOobeUI() const;
96 const gfx::Rect& background_bounds() const { return background_bounds_; }
98 // Trace id for ShowLoginWebUI event (since there exists at most one login
100 static const int kShowLoginWebUIid;
102 views::Widget* login_window_for_test() { return login_window_; }
105 // content::NotificationObserver implementation:
106 virtual void Observe(int type,
107 const content::NotificationSource& source,
108 const content::NotificationDetails& details) OVERRIDE;
110 // Overridden from content::WebContentsObserver:
111 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
113 // Overridden from chromeos::SessionManagerClient::Observer:
114 virtual void EmitLoginPromptVisibleCalled() OVERRIDE;
116 // Overridden from chromeos::CrasAudioHandler::AudioObserver:
117 virtual void OnActiveOutputNodeChanged() OVERRIDE;
120 // Way to restore if renderer have crashed.
125 RESTORE_ADD_USER_INTO_SESSION,
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.
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);
140 // Schedules workspace transition animation.
141 void ScheduleWorkspaceAnimation();
143 // Schedules fade out animation.
144 void ScheduleFadeOutAnimation();
146 // Callback for the ownership status check.
147 void OnOwnershipStatusCheckDone(
148 DeviceSettingsService::OwnershipStatus status);
150 // Callback for completion of the |auto_enrollment_client_|.
151 void OnAutoEnrollmentClientDone();
153 // Forces auto-enrollment on the appropriate controller.
154 void ForceAutoEnrollment();
156 // Loads given URL. Creates WebUILoginView if needed.
157 void LoadURL(const GURL& url);
159 // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
162 // Starts postponed WebUI (OOBE/sign in) if it was waiting for
163 // wallpaper animation end.
164 void StartPostponedWebUI();
166 // Initializes |login_window_| and |login_view_| fields if needed.
167 void InitLoginWindowAndView();
169 // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
170 void ResetLoginWindowAndView();
172 // Deletes |auth_prewarmer_|.
173 void OnAuthPrewarmDone();
175 // Toggles OOBE progress bar visibility, the bar is hidden by default.
176 void SetOobeProgressBarVisible(bool visible);
178 // Notifies the interested parties of the auto enrollment check result.
179 void NotifyAutoEnrollmentCheckResult(bool should_auto_enroll);
181 // Tries to play startup sound. If sound can't be played right now,
182 // for instance, because cras server is not initialized, playback
184 void TryToPlayStartupSound();
186 // Called when login-prompt-visible signal is caught.
187 void OnLoginPromptVisible();
189 // Used to calculate position of the screens and background.
190 gfx::Rect background_bounds_;
192 content::NotificationRegistrar registrar_;
194 base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_;
196 // Default LoginDisplayHost.
197 static LoginDisplayHost* default_host_;
199 // Sign in screen controller.
200 scoped_ptr<ExistingUserController> sign_in_controller_;
202 // OOBE and some screens (camera, recovery) controller.
203 scoped_ptr<WizardController> wizard_controller_;
205 // App launch controller.
206 scoped_ptr<AppLaunchController> app_launch_controller_;
208 // Demo app launcher.
209 scoped_ptr<DemoAppLauncher> demo_app_launcher_;
211 // Client for enterprise auto-enrollment check.
212 scoped_ptr<policy::AutoEnrollmentClient> auto_enrollment_client_;
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).
219 // Whether progress bar is shown on the OOBE page.
220 bool oobe_progress_bar_visible_;
222 // True if session start is in progress.
223 bool session_starting_;
225 // Container of the screen we are displaying.
226 views::Widget* login_window_;
228 // Container of the view we are displaying.
229 WebUILoginView* login_view_;
231 // Login display we are using.
232 WebUILoginDisplay* webui_login_display_;
234 // True if the login display is the current screen.
235 bool is_showing_login_;
237 // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
239 bool is_wallpaper_loaded_;
241 // Stores status area current visibility to be applied once login WebUI
243 bool status_area_saved_visibility_;
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_;
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_;
255 // True if WebUI is initialized in hidden state and we're waiting for user
257 bool waiting_for_user_pods_;
259 // How many times renderer has crashed.
262 // Way to restore if renderer have crashed.
263 RestorePath restore_path_;
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_;
269 // Called before host deletion.
270 base::Closure completion_callback_;
272 // Active instance of authentication prewarmer.
273 scoped_ptr<AuthPrewarmer> auth_prewarmer_;
275 // A focus ring controller to draw focus ring around view for keyboard
277 scoped_ptr<FocusRingController> focus_ring_controller_;
279 // Handles special keys for keyboard driven oobe.
280 scoped_ptr<KeyboardDrivenOobeKeyHandler> keyboard_driven_oobe_key_handler_;
282 // Whether auto enrollment client has done the check.
283 bool auto_enrollment_check_done_;
285 // Callbacks to notify when auto enrollment client has done the check.
286 std::vector<GetAutoEnrollmentCheckResultCallback>
287 get_auto_enrollment_result_callbacks_;
289 FinalizeAnimationType finalize_animation_type_;
291 base::WeakPtrFactory<LoginDisplayHostImpl> animation_weak_ptr_factory_;
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_;
297 // True when request to play startup sound was sent to
299 bool startup_sound_played_;
301 // When true, startup sound should be played only when spoken
302 // feedback is enabled. Otherwise, startup sound should be played
304 bool startup_sound_honors_spoken_feedback_;
306 DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl);
309 } // namespace chromeos
311 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_