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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_HOST_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_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/auth_prewarmer.h"
16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
17 #include "chrome/browser/chromeos/login/ui/login_display.h"
18 #include "chrome/browser/chromeos/login/ui/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/display_observer.h"
27 #include "ui/gfx/rect.h"
28 #include "ui/keyboard/keyboard_controller_observer.h"
29 #include "ui/views/widget/widget_removals_observer.h"
31 #if !defined(USE_ATHENA)
32 #include "ash/shell_delegate.h"
38 class RenderFrameHost;
44 class DemoAppLauncher;
45 class FocusRingController;
47 class WebUILoginDisplay;
50 #if !defined(USE_ATHENA)
51 class KeyboardDrivenOobeKeyHandler;
54 // An implementation class for OOBE/login WebUI screen host.
55 // It encapsulates controllers, background integration and flow.
56 class LoginDisplayHostImpl : public LoginDisplayHost,
57 public content::NotificationObserver,
58 public content::WebContentsObserver,
59 public chromeos::SessionManagerClient::Observer,
60 public chromeos::CrasAudioHandler::AudioObserver,
61 #if !defined(USE_ATHENA)
62 public ash::VirtualKeyboardStateObserver,
64 public keyboard::KeyboardControllerObserver,
65 public gfx::DisplayObserver,
66 public views::WidgetRemovalsObserver {
68 explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds);
69 virtual ~LoginDisplayHostImpl();
71 // Returns the default LoginDisplayHost instance if it has been created.
72 static LoginDisplayHost* default_host() {
76 // LoginDisplayHost implementation:
77 virtual LoginDisplay* CreateLoginDisplay(
78 LoginDisplay::Delegate* delegate) override;
79 virtual gfx::NativeWindow GetNativeWindow() const override;
80 virtual WebUILoginView* GetWebUILoginView() const override;
81 virtual void BeforeSessionStart() override;
82 virtual void Finalize() override;
83 virtual void OnCompleteLogin() override;
84 virtual void OpenProxySettings() override;
85 virtual void SetStatusAreaVisible(bool visible) override;
86 virtual AutoEnrollmentController* GetAutoEnrollmentController() override;
87 virtual void StartWizard(
88 const std::string& first_screen_name,
89 scoped_ptr<base::DictionaryValue> screen_parameters) override;
90 virtual WizardController* GetWizardController() override;
91 virtual AppLaunchController* GetAppLaunchController() override;
92 virtual void StartUserAdding(
93 const base::Closure& completion_callback) override;
94 virtual void StartSignInScreen(const LoginScreenContext& context) override;
95 virtual void ResumeSignInScreen() override;
96 virtual void OnPreferencesChanged() override;
97 virtual void PrewarmAuthentication() override;
98 virtual void StartAppLaunch(const std::string& app_id,
99 bool diagnostic_mode) override;
100 virtual void StartDemoAppLaunch() override;
102 // Creates WizardController instance.
103 WizardController* CreateWizardController();
105 // Called when the first browser window is created, but before it's shown.
106 void OnBrowserCreated();
108 // Returns instance of the OOBE WebUI.
109 OobeUI* GetOobeUI() const;
111 const gfx::Rect& background_bounds() const { return background_bounds_; }
113 // Trace id for ShowLoginWebUI event (since there exists at most one login
115 static const int kShowLoginWebUIid;
117 views::Widget* login_window_for_test() { return login_window_; }
120 // content::NotificationObserver implementation:
121 virtual void Observe(int type,
122 const content::NotificationSource& source,
123 const content::NotificationDetails& details) override;
125 // Overridden from content::WebContentsObserver:
126 virtual void RenderProcessGone(base::TerminationStatus status) override;
128 // Overridden from chromeos::SessionManagerClient::Observer:
129 virtual void EmitLoginPromptVisibleCalled() override;
131 // Overridden from chromeos::CrasAudioHandler::AudioObserver:
132 virtual void OnActiveOutputNodeChanged() override;
134 #if !defined(USE_ATHENA)
135 // Overridden from ash::KeyboardStateObserver:
136 virtual void OnVirtualKeyboardStateChanged(bool activated) override;
139 // Overridden from keyboard::KeyboardControllerObserver:
140 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override;
142 // Overridden from gfx::DisplayObserver:
143 virtual void OnDisplayAdded(const gfx::Display& new_display) override;
144 virtual void OnDisplayRemoved(const gfx::Display& old_display) override;
145 virtual void OnDisplayMetricsChanged(const gfx::Display& display,
146 uint32_t changed_metrics) override;
148 // Overriden from views::WidgetRemovalsObserver:
149 virtual void OnWillRemoveView(views::Widget* widget,
150 views::View* view) override;
153 // Way to restore if renderer have crashed.
158 RESTORE_ADD_USER_INTO_SESSION,
161 // Type of animations to run after the login screen.
162 enum FinalizeAnimationType {
163 ANIMATION_NONE, // No animation.
164 ANIMATION_WORKSPACE, // Use initial workspace animation (drop and
165 // and fade in workspace). Used for user login.
166 ANIMATION_FADE_OUT, // Fade out login screen. Used for app launch.
169 // Marks display host for deletion.
170 // If |post_quit_task| is true also posts Quit task to the MessageLoop.
171 void ShutdownDisplayHost(bool post_quit_task);
173 // Schedules workspace transition animation.
174 void ScheduleWorkspaceAnimation();
176 // Schedules fade out animation.
177 void ScheduleFadeOutAnimation();
179 // Progress callback registered with |auto_enrollment_controller_|.
180 void OnAutoEnrollmentProgress(policy::AutoEnrollmentState state);
182 // Loads given URL. Creates WebUILoginView if needed.
183 void LoadURL(const GURL& url);
185 // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
188 // Starts postponed WebUI (OOBE/sign in) if it was waiting for
189 // wallpaper animation end.
190 void StartPostponedWebUI();
192 // Initializes |login_window_| and |login_view_| fields if needed.
193 void InitLoginWindowAndView();
195 // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
196 void ResetLoginWindowAndView();
198 // Deletes |auth_prewarmer_|.
199 void OnAuthPrewarmDone();
201 // Toggles OOBE progress bar visibility, the bar is hidden by default.
202 void SetOobeProgressBarVisible(bool visible);
204 // Tries to play startup sound. If sound can't be played right now,
205 // for instance, because cras server is not initialized, playback
207 void TryToPlayStartupSound();
209 // Called when login-prompt-visible signal is caught.
210 void OnLoginPromptVisible();
212 // Used to calculate position of the screens and background.
213 gfx::Rect background_bounds_;
215 content::NotificationRegistrar registrar_;
217 base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_;
219 // Default LoginDisplayHost.
220 static LoginDisplayHost* default_host_;
222 // The controller driving the auto-enrollment check.
223 scoped_ptr<AutoEnrollmentController> auto_enrollment_controller_;
225 // Subscription for progress callbacks from |auto_enrollement_controller_|.
226 scoped_ptr<AutoEnrollmentController::ProgressCallbackList::Subscription>
227 auto_enrollment_progress_subscription_;
229 // Sign in screen controller.
230 scoped_ptr<ExistingUserController> sign_in_controller_;
232 // OOBE and some screens (camera, recovery) controller.
233 scoped_ptr<WizardController> wizard_controller_;
235 // App launch controller.
236 scoped_ptr<AppLaunchController> app_launch_controller_;
238 // Demo app launcher.
239 scoped_ptr<DemoAppLauncher> demo_app_launcher_;
241 // Has ShutdownDisplayHost() already been called? Used to avoid posting our
242 // own deletion to the message loop twice if the user logs out while we're
243 // still in the process of cleaning up after login (http://crbug.com/134463).
246 // Whether progress bar is shown on the OOBE page.
247 bool oobe_progress_bar_visible_;
249 // True if session start is in progress.
250 bool session_starting_;
252 // Container of the screen we are displaying.
253 views::Widget* login_window_;
255 // Container of the view we are displaying.
256 WebUILoginView* login_view_;
258 // Login display we are using.
259 WebUILoginDisplay* webui_login_display_;
261 // True if the login display is the current screen.
262 bool is_showing_login_;
264 // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
266 bool is_wallpaper_loaded_;
268 // Stores status area current visibility to be applied once login WebUI
270 bool status_area_saved_visibility_;
272 // If true, WebUI is initialized in a hidden state and shown after the
273 // wallpaper animation is finished (when it is enabled) or the user pods have
274 // been loaded (otherwise).
275 // By default is true. Could be used to tune performance if needed.
276 bool initialize_webui_hidden_;
278 // True if WebUI is initialized in hidden state and we're waiting for
279 // wallpaper load animation to finish.
280 bool waiting_for_wallpaper_load_;
282 // True if WebUI is initialized in hidden state and we're waiting for user
284 bool waiting_for_user_pods_;
286 // How many times renderer has crashed.
289 // Way to restore if renderer have crashed.
290 RestorePath restore_path_;
292 // Stored parameters for StartWizard, required to restore in case of crash.
293 std::string first_screen_name_;
294 scoped_ptr<base::DictionaryValue> screen_parameters_;
296 // Called before host deletion.
297 base::Closure completion_callback_;
299 // Active instance of authentication prewarmer.
300 scoped_ptr<AuthPrewarmer> auth_prewarmer_;
302 // A focus ring controller to draw focus ring around view for keyboard
304 scoped_ptr<FocusRingController> focus_ring_controller_;
306 #if !defined(USE_ATHENA)
307 // Handles special keys for keyboard driven oobe.
308 scoped_ptr<KeyboardDrivenOobeKeyHandler> keyboard_driven_oobe_key_handler_;
311 FinalizeAnimationType finalize_animation_type_;
313 // Time when login prompt visible signal is received. Used for
314 // calculations of delay before startup sound.
315 base::TimeTicks login_prompt_visible_time_;
317 // True when request to play startup sound was sent to
319 bool startup_sound_played_;
321 // When true, startup sound should be played only when spoken
322 // feedback is enabled. Otherwise, startup sound should be played
324 bool startup_sound_honors_spoken_feedback_;
326 // True is subscribed as keyboard controller observer.
327 bool is_observing_keyboard_;
329 // The bounds of the virtual keyboard.
330 gfx::Rect keyboard_bounds_;
332 #if defined(USE_ATHENA)
333 scoped_ptr<aura::Window> login_screen_container_;
336 base::WeakPtrFactory<LoginDisplayHostImpl> animation_weak_ptr_factory_;
338 DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl);
341 } // namespace chromeos
343 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_HOST_IMPL_H_