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