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 "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"
32 #include "ui/wm/public/scoped_drag_drop_disabler.h"
37 class RenderFrameHost
;
43 class DemoAppLauncher
;
44 class FocusRingController
;
45 class KeyboardDrivenOobeKeyHandler
;
47 class WebUILoginDisplay
;
50 // An implementation class for OOBE/login WebUI screen host.
51 // It encapsulates controllers, background integration and flow.
52 class LoginDisplayHostImpl
: public LoginDisplayHost
,
53 public content::NotificationObserver
,
54 public content::WebContentsObserver
,
55 public chromeos::SessionManagerClient::Observer
,
56 public chromeos::CrasAudioHandler::AudioObserver
,
57 public ash::VirtualKeyboardStateObserver
,
58 public keyboard::KeyboardControllerObserver
,
59 public gfx::DisplayObserver
,
60 public views::WidgetRemovalsObserver
{
62 explicit LoginDisplayHostImpl(const gfx::Rect
& background_bounds
);
63 ~LoginDisplayHostImpl() override
;
65 // Returns the default LoginDisplayHost instance if it has been created.
66 static LoginDisplayHost
* default_host() {
70 // LoginDisplayHost implementation:
71 LoginDisplay
* CreateLoginDisplay(LoginDisplay::Delegate
* delegate
) override
;
72 gfx::NativeWindow
GetNativeWindow() const override
;
73 WebUILoginView
* GetWebUILoginView() const override
;
74 void BeforeSessionStart() override
;
75 void Finalize() override
;
76 void OnCompleteLogin() override
;
77 void OpenProxySettings() override
;
78 void SetStatusAreaVisible(bool visible
) override
;
79 AutoEnrollmentController
* GetAutoEnrollmentController() override
;
80 void StartWizard(const std::string
& first_screen_name
) override
;
81 WizardController
* GetWizardController() override
;
82 AppLaunchController
* GetAppLaunchController() override
;
83 void StartUserAdding(const base::Closure
& completion_callback
) override
;
84 void StartSignInScreen(const LoginScreenContext
& context
) override
;
85 void OnPreferencesChanged() override
;
86 void PrewarmAuthentication() override
;
88 const std::string
& app_id
,
90 bool auto_launch
) override
;
91 void StartDemoAppLaunch() override
;
93 // Creates WizardController instance.
94 WizardController
* CreateWizardController();
96 // Called when the first browser window is created, but before it's shown.
97 void OnBrowserCreated();
99 // Returns instance of the OOBE WebUI.
100 OobeUI
* GetOobeUI() const;
102 const gfx::Rect
& background_bounds() const { return background_bounds_
; }
104 // Trace id for ShowLoginWebUI event (since there exists at most one login
106 static const int kShowLoginWebUIid
;
108 views::Widget
* login_window_for_test() { return login_window_
; }
110 void StartTimeZoneResolve();
113 // content::NotificationObserver implementation:
114 void Observe(int type
,
115 const content::NotificationSource
& source
,
116 const content::NotificationDetails
& details
) override
;
118 // Overridden from content::WebContentsObserver:
119 void RenderProcessGone(base::TerminationStatus status
) override
;
121 // Overridden from chromeos::SessionManagerClient::Observer:
122 void EmitLoginPromptVisibleCalled() override
;
124 // Overridden from chromeos::CrasAudioHandler::AudioObserver:
125 void OnActiveOutputNodeChanged() override
;
127 // Overridden from ash::KeyboardStateObserver:
128 void OnVirtualKeyboardStateChanged(bool activated
) override
;
130 // Overridden from keyboard::KeyboardControllerObserver:
131 void OnKeyboardBoundsChanging(const gfx::Rect
& new_bounds
) override
;
133 // Overridden from gfx::DisplayObserver:
134 void OnDisplayAdded(const gfx::Display
& new_display
) override
;
135 void OnDisplayRemoved(const gfx::Display
& old_display
) override
;
136 void OnDisplayMetricsChanged(const gfx::Display
& display
,
137 uint32_t changed_metrics
) override
;
139 // Overriden from views::WidgetRemovalsObserver:
140 void OnWillRemoveView(views::Widget
* widget
, views::View
* view
) override
;
143 // Way to restore if renderer have crashed.
148 RESTORE_ADD_USER_INTO_SESSION
,
151 // Type of animations to run after the login screen.
152 enum FinalizeAnimationType
{
153 ANIMATION_NONE
, // No animation.
154 ANIMATION_WORKSPACE
, // Use initial workspace animation (drop and
155 // and fade in workspace). Used for user login.
156 ANIMATION_FADE_OUT
, // Fade out login screen. Used for app launch.
159 // Marks display host for deletion.
160 // If |post_quit_task| is true also posts Quit task to the MessageLoop.
161 void ShutdownDisplayHost(bool post_quit_task
);
163 // Schedules workspace transition animation.
164 void ScheduleWorkspaceAnimation();
166 // Schedules fade out animation.
167 void ScheduleFadeOutAnimation();
169 // Loads given URL. Creates WebUILoginView if needed.
170 void LoadURL(const GURL
& url
);
172 // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
175 // Starts postponed WebUI (OOBE/sign in) if it was waiting for
176 // wallpaper animation end.
177 void StartPostponedWebUI();
179 // Initializes |login_window_| and |login_view_| fields if needed.
180 void InitLoginWindowAndView();
182 // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
183 void ResetLoginWindowAndView();
185 // Deletes |auth_prewarmer_|.
186 void OnAuthPrewarmDone();
188 // Toggles OOBE progress bar visibility, the bar is hidden by default.
189 void SetOobeProgressBarVisible(bool visible
);
191 // Tries to play startup sound. If sound can't be played right now,
192 // for instance, because cras server is not initialized, playback
194 void TryToPlayStartupSound();
196 // Called when login-prompt-visible signal is caught.
197 void OnLoginPromptVisible();
199 // Used to calculate position of the screens and background.
200 gfx::Rect background_bounds_
;
202 content::NotificationRegistrar registrar_
;
204 // Default LoginDisplayHost.
205 static LoginDisplayHost
* default_host_
;
207 // The controller driving the auto-enrollment check.
208 scoped_ptr
<AutoEnrollmentController
> auto_enrollment_controller_
;
210 // Sign in screen controller.
211 scoped_ptr
<ExistingUserController
> existing_user_controller_
;
213 // OOBE and some screens (camera, recovery) controller.
214 scoped_ptr
<WizardController
> wizard_controller_
;
216 scoped_ptr
<SignInScreenController
> signin_screen_controller_
;
218 // App launch controller.
219 scoped_ptr
<AppLaunchController
> app_launch_controller_
;
221 // Demo app launcher.
222 scoped_ptr
<DemoAppLauncher
> demo_app_launcher_
;
224 // Has ShutdownDisplayHost() already been called? Used to avoid posting our
225 // own deletion to the message loop twice if the user logs out while we're
226 // still in the process of cleaning up after login (http://crbug.com/134463).
229 // Whether progress bar is shown on the OOBE page.
230 bool oobe_progress_bar_visible_
;
232 // True if session start is in progress.
233 bool session_starting_
;
235 // Container of the screen we are displaying.
236 views::Widget
* login_window_
;
238 // Container of the view we are displaying.
239 WebUILoginView
* login_view_
;
241 // Login display we are using.
242 WebUILoginDisplay
* webui_login_display_
;
244 // True if the login display is the current screen.
245 bool is_showing_login_
;
247 // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
249 bool is_wallpaper_loaded_
;
251 // Stores status area current visibility to be applied once login WebUI
253 bool status_area_saved_visibility_
;
255 // If true, WebUI is initialized in a hidden state and shown after the
256 // wallpaper animation is finished (when it is enabled) or the user pods have
257 // been loaded (otherwise).
258 // By default is true. Could be used to tune performance if needed.
259 bool initialize_webui_hidden_
;
261 // True if WebUI is initialized in hidden state and we're waiting for
262 // wallpaper load animation to finish.
263 bool waiting_for_wallpaper_load_
;
265 // True if WebUI is initialized in hidden state and we're waiting for user
267 bool waiting_for_user_pods_
;
269 // How many times renderer has crashed.
272 // Way to restore if renderer have crashed.
273 RestorePath restore_path_
;
275 // Stored parameters for StartWizard, required to restore in case of crash.
276 std::string first_screen_name_
;
278 // Called before host deletion.
279 base::Closure completion_callback_
;
281 // Active instance of authentication prewarmer.
282 scoped_ptr
<AuthPrewarmer
> auth_prewarmer_
;
284 // A focus ring controller to draw focus ring around view for keyboard
286 scoped_ptr
<FocusRingController
> focus_ring_controller_
;
288 // Handles special keys for keyboard driven oobe.
289 scoped_ptr
<KeyboardDrivenOobeKeyHandler
> keyboard_driven_oobe_key_handler_
;
291 FinalizeAnimationType finalize_animation_type_
;
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 // True is subscribed as keyboard controller observer.
307 bool is_observing_keyboard_
;
309 // Keeps a copy of the old Drag'n'Drop client, so that it would be disabled
310 // during a login session and restored afterwards.
311 scoped_ptr
<aura::client::ScopedDragDropDisabler
> scoped_drag_drop_disabler_
;
313 base::WeakPtrFactory
<LoginDisplayHostImpl
> pointer_factory_
;
314 base::WeakPtrFactory
<LoginDisplayHostImpl
> animation_weak_ptr_factory_
;
316 DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl
);
319 } // namespace chromeos
321 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_HOST_IMPL_H_