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/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"
31 class AutoEnrollmentClient
;
36 class FocusRingController
;
37 class KeyboardDrivenOobeKeyHandler
;
39 class WebUILoginDisplay
;
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
{
50 explicit LoginDisplayHostImpl(const gfx::Rect
& background_bounds
);
51 virtual ~LoginDisplayHostImpl();
53 // Returns the default LoginDispalyHost instance if it has been created.
54 static LoginDisplayHost
* default_host() {
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
<base::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
;
84 // Creates WizardController instance.
85 WizardController
* CreateWizardController();
87 // Called when the first browser window is created, but before it's shown.
88 void OnBrowserCreated();
90 // Returns instance of the OOBE WebUI.
91 OobeUI
* GetOobeUI() const;
93 const gfx::Rect
& background_bounds() const { return background_bounds_
; }
95 // Trace id for ShowLoginWebUI event (since there exists at most one login
97 static const int kShowLoginWebUIid
;
99 views::Widget
* login_window_for_test() { return login_window_
; }
102 // content::NotificationObserver implementation:
103 virtual void Observe(int type
,
104 const content::NotificationSource
& source
,
105 const content::NotificationDetails
& details
) OVERRIDE
;
107 // Overridden from content::WebContentsObserver:
108 virtual void RenderProcessGone(base::TerminationStatus status
) OVERRIDE
;
110 // Overridden from chromeos::SessionManagerClient::Observer:
111 virtual void EmitLoginPromptVisibleCalled() OVERRIDE
;
113 // Overridden from chromeos::CrasAudioHandler::AudioObserver:
114 virtual void OnActiveOutputNodeChanged() OVERRIDE
;
117 // Way to restore if renderer have crashed.
122 RESTORE_ADD_USER_INTO_SESSION
,
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.
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
);
137 // Schedules workspace transition animation.
138 void ScheduleWorkspaceAnimation();
140 // Schedules fade out animation.
141 void ScheduleFadeOutAnimation();
143 // Callback for the ownership status check.
144 void OnOwnershipStatusCheckDone(
145 DeviceSettingsService::OwnershipStatus status
);
147 // Callback for completion of the |auto_enrollment_client_|.
148 void OnAutoEnrollmentClientDone();
150 // Forces auto-enrollment on the appropriate controller.
151 void ForceAutoEnrollment();
153 // Loads given URL. Creates WebUILoginView if needed.
154 void LoadURL(const GURL
& url
);
156 // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
159 // Starts postponed WebUI (OOBE/sign in) if it was waiting for
160 // wallpaper animation end.
161 void StartPostponedWebUI();
163 // Initializes |login_window_| and |login_view_| fields if needed.
164 void InitLoginWindowAndView();
166 // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
167 void ResetLoginWindowAndView();
169 // Deletes |auth_prewarmer_|.
170 void OnAuthPrewarmDone();
172 // Toggles OOBE progress bar visibility, the bar is hidden by default.
173 void SetOobeProgressBarVisible(bool visible
);
175 // Notifies the interested parties of the auto enrollment check result.
176 void NotifyAutoEnrollmentCheckResult(bool should_auto_enroll
);
178 // Tries to play startup sound. If sound can't be played right now,
179 // for instance, because cras server is not initialized, playback
181 void TryToPlayStartupSound();
183 // Called when login-prompt-visible signal is caught.
184 void OnLoginPromptVisible();
186 // Used to calculate position of the screens and background.
187 gfx::Rect background_bounds_
;
189 content::NotificationRegistrar registrar_
;
191 base::WeakPtrFactory
<LoginDisplayHostImpl
> pointer_factory_
;
193 // Default LoginDisplayHost.
194 static LoginDisplayHost
* default_host_
;
196 // Sign in screen controller.
197 scoped_ptr
<ExistingUserController
> sign_in_controller_
;
199 // OOBE and some screens (camera, recovery) controller.
200 scoped_ptr
<WizardController
> wizard_controller_
;
202 // App launch controller.
203 scoped_ptr
<AppLaunchController
> app_launch_controller_
;
205 // Client for enterprise auto-enrollment check.
206 scoped_ptr
<policy::AutoEnrollmentClient
> auto_enrollment_client_
;
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).
213 // Whether progress bar is shown on the OOBE page.
214 bool oobe_progress_bar_visible_
;
216 // True if session start is in progress.
217 bool session_starting_
;
219 // Container of the screen we are displaying.
220 views::Widget
* login_window_
;
222 // Container of the view we are displaying.
223 WebUILoginView
* login_view_
;
225 // Login display we are using.
226 WebUILoginDisplay
* webui_login_display_
;
228 // True if the login display is the current screen.
229 bool is_showing_login_
;
231 // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
233 bool is_wallpaper_loaded_
;
235 // Stores status area current visibility to be applied once login WebUI
237 bool status_area_saved_visibility_
;
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_
;
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_
;
249 // True if WebUI is initialized in hidden state and we're waiting for user
251 bool waiting_for_user_pods_
;
253 // How many times renderer has crashed.
256 // Way to restore if renderer have crashed.
257 RestorePath restore_path_
;
259 // Stored parameters for StartWizard, required to restore in case of crash.
260 std::string wizard_first_screen_name_
;
261 scoped_ptr
<base::DictionaryValue
> wizard_screen_parameters_
;
263 // Called before host deletion.
264 base::Closure completion_callback_
;
266 // Active instance of authentication prewarmer.
267 scoped_ptr
<AuthPrewarmer
> auth_prewarmer_
;
269 // A focus ring controller to draw focus ring around view for keyboard
271 scoped_ptr
<FocusRingController
> focus_ring_controller_
;
273 // Handles special keys for keyboard driven oobe.
274 scoped_ptr
<KeyboardDrivenOobeKeyHandler
> keyboard_driven_oobe_key_handler_
;
276 // Whether auto enrollment client has done the check.
277 bool auto_enrollment_check_done_
;
279 // Callbacks to notify when auto enrollment client has done the check.
280 std::vector
<GetAutoEnrollmentCheckResultCallback
>
281 get_auto_enrollment_result_callbacks_
;
283 FinalizeAnimationType finalize_animation_type_
;
285 base::WeakPtrFactory
<LoginDisplayHostImpl
> animation_weak_ptr_factory_
;
287 // Time when login prompt visible signal is received. Used for
288 // calculations of delay before startup sound.
289 base::TimeTicks login_prompt_visible_time_
;
291 // True when request to play startup sound was sent to
293 bool startup_sound_played_
;
295 // When true, startup sound should be played only when spoken
296 // feedback is enabled. Otherwise, startup sound should be played
298 bool startup_sound_honors_spoken_feedback_
;
300 DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl
);
303 } // namespace chromeos
305 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_