| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 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_prewarmer.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" | |
| 28 #include "ui/keyboard/keyboard_controller_observer.h" | |
| 29 | |
| 30 class PrefService; | |
| 31 | |
| 32 namespace content { | |
| 33 class RenderFrameHost; | |
| 34 class WebContents; | |
| 35 } | |
| 36 | |
| 37 namespace chromeos { | |
| 38 | |
| 39 class DemoAppLauncher; | |
| 40 class FocusRingController; | |
| 41 class KeyboardDrivenOobeKeyHandler; | |
| 42 class OobeUI; | |
| 43 class WebUILoginDisplay; | |
| 44 class WebUILoginView; | |
| 45 | |
| 46 // An implementation class for OOBE/login WebUI screen host. | |
| 47 // It encapsulates controllers, background integration and flow. | |
| 48 class LoginDisplayHostImpl : public LoginDisplayHost, | |
| 49 public content::NotificationObserver, | |
| 50 public content::WebContentsObserver, | |
| 51 public chromeos::SessionManagerClient::Observer, | |
| 52 public chromeos::CrasAudioHandler::AudioObserver, | |
| 53 public ash::VirtualKeyboardStateObserver, | |
| 54 public keyboard::KeyboardControllerObserver { | |
| 55 public: | |
| 56 explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds); | |
| 57 virtual ~LoginDisplayHostImpl(); | |
| 58 | |
| 59 // Returns the default LoginDisplayHost instance if it has been created. | |
| 60 static LoginDisplayHost* default_host() { | |
| 61 return default_host_; | |
| 62 } | |
| 63 | |
| 64 // Gets the Gaia auth iframe within a WebContents. | |
| 65 static content::RenderFrameHost* GetGaiaAuthIframe( | |
| 66 content::WebContents* web_contents); | |
| 67 | |
| 68 // LoginDisplayHost implementation: | |
| 69 virtual LoginDisplay* CreateLoginDisplay( | |
| 70 LoginDisplay::Delegate* delegate) OVERRIDE; | |
| 71 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE; | |
| 72 virtual WebUILoginView* GetWebUILoginView() const OVERRIDE; | |
| 73 virtual void BeforeSessionStart() OVERRIDE; | |
| 74 virtual void Finalize() OVERRIDE; | |
| 75 virtual void OnCompleteLogin() OVERRIDE; | |
| 76 virtual void OpenProxySettings() OVERRIDE; | |
| 77 virtual void SetStatusAreaVisible(bool visible) OVERRIDE; | |
| 78 virtual AutoEnrollmentController* GetAutoEnrollmentController() OVERRIDE; | |
| 79 virtual void StartWizard( | |
| 80 const std::string& first_screen_name, | |
| 81 scoped_ptr<base::DictionaryValue> screen_parameters) OVERRIDE; | |
| 82 virtual WizardController* GetWizardController() OVERRIDE; | |
| 83 virtual AppLaunchController* GetAppLaunchController() OVERRIDE; | |
| 84 virtual void StartUserAdding( | |
| 85 const base::Closure& completion_callback) OVERRIDE; | |
| 86 virtual void StartSignInScreen(const LoginScreenContext& context) OVERRIDE; | |
| 87 virtual void ResumeSignInScreen() OVERRIDE; | |
| 88 virtual void OnPreferencesChanged() OVERRIDE; | |
| 89 virtual void PrewarmAuthentication() OVERRIDE; | |
| 90 virtual void StartAppLaunch(const std::string& app_id, | |
| 91 bool diagnostic_mode) OVERRIDE; | |
| 92 virtual void StartDemoAppLaunch() OVERRIDE; | |
| 93 | |
| 94 // Creates WizardController instance. | |
| 95 WizardController* CreateWizardController(); | |
| 96 | |
| 97 // Called when the first browser window is created, but before it's shown. | |
| 98 void OnBrowserCreated(); | |
| 99 | |
| 100 // Returns instance of the OOBE WebUI. | |
| 101 OobeUI* GetOobeUI() const; | |
| 102 | |
| 103 const gfx::Rect& background_bounds() const { return background_bounds_; } | |
| 104 | |
| 105 // Trace id for ShowLoginWebUI event (since there exists at most one login | |
| 106 // WebUI at a time). | |
| 107 static const int kShowLoginWebUIid; | |
| 108 | |
| 109 views::Widget* login_window_for_test() { return login_window_; } | |
| 110 | |
| 111 protected: | |
| 112 // content::NotificationObserver implementation: | |
| 113 virtual void Observe(int type, | |
| 114 const content::NotificationSource& source, | |
| 115 const content::NotificationDetails& details) OVERRIDE; | |
| 116 | |
| 117 // Overridden from content::WebContentsObserver: | |
| 118 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; | |
| 119 | |
| 120 // Overridden from chromeos::SessionManagerClient::Observer: | |
| 121 virtual void EmitLoginPromptVisibleCalled() OVERRIDE; | |
| 122 | |
| 123 // Overridden from chromeos::CrasAudioHandler::AudioObserver: | |
| 124 virtual void OnActiveOutputNodeChanged() OVERRIDE; | |
| 125 | |
| 126 // Overridden from ash::KeyboardStateObserver: | |
| 127 virtual void OnVirtualKeyboardStateChanged(bool activated) OVERRIDE; | |
| 128 | |
| 129 // Overridden from keyboard::KeyboardControllerObserver: | |
| 130 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE; | |
| 131 | |
| 132 private: | |
| 133 // Way to restore if renderer have crashed. | |
| 134 enum RestorePath { | |
| 135 RESTORE_UNKNOWN, | |
| 136 RESTORE_WIZARD, | |
| 137 RESTORE_SIGN_IN, | |
| 138 RESTORE_ADD_USER_INTO_SESSION, | |
| 139 }; | |
| 140 | |
| 141 // Type of animations to run after the login screen. | |
| 142 enum FinalizeAnimationType { | |
| 143 ANIMATION_NONE, // No animation. | |
| 144 ANIMATION_WORKSPACE, // Use initial workspace animation (drop and | |
| 145 // and fade in workspace). Used for user login. | |
| 146 ANIMATION_FADE_OUT, // Fade out login screen. Used for app launch. | |
| 147 }; | |
| 148 | |
| 149 // Marks display host for deletion. | |
| 150 // If |post_quit_task| is true also posts Quit task to the MessageLoop. | |
| 151 void ShutdownDisplayHost(bool post_quit_task); | |
| 152 | |
| 153 // Schedules workspace transition animation. | |
| 154 void ScheduleWorkspaceAnimation(); | |
| 155 | |
| 156 // Schedules fade out animation. | |
| 157 void ScheduleFadeOutAnimation(); | |
| 158 | |
| 159 // Progress callback registered with |auto_enrollment_controller_|. | |
| 160 void OnAutoEnrollmentProgress(policy::AutoEnrollmentState state); | |
| 161 | |
| 162 // Loads given URL. Creates WebUILoginView if needed. | |
| 163 void LoadURL(const GURL& url); | |
| 164 | |
| 165 // Shows OOBE/sign in WebUI that was previously initialized in hidden state. | |
| 166 void ShowWebUI(); | |
| 167 | |
| 168 // Starts postponed WebUI (OOBE/sign in) if it was waiting for | |
| 169 // wallpaper animation end. | |
| 170 void StartPostponedWebUI(); | |
| 171 | |
| 172 // Initializes |login_window_| and |login_view_| fields if needed. | |
| 173 void InitLoginWindowAndView(); | |
| 174 | |
| 175 // Closes |login_window_| and resets |login_window_| and |login_view_| fields. | |
| 176 void ResetLoginWindowAndView(); | |
| 177 | |
| 178 // Deletes |auth_prewarmer_|. | |
| 179 void OnAuthPrewarmDone(); | |
| 180 | |
| 181 // Toggles OOBE progress bar visibility, the bar is hidden by default. | |
| 182 void SetOobeProgressBarVisible(bool visible); | |
| 183 | |
| 184 // Tries to play startup sound. If sound can't be played right now, | |
| 185 // for instance, because cras server is not initialized, playback | |
| 186 // will be delayed. | |
| 187 void TryToPlayStartupSound(); | |
| 188 | |
| 189 // Called when login-prompt-visible signal is caught. | |
| 190 void OnLoginPromptVisible(); | |
| 191 | |
| 192 // Used to calculate position of the screens and background. | |
| 193 gfx::Rect background_bounds_; | |
| 194 | |
| 195 content::NotificationRegistrar registrar_; | |
| 196 | |
| 197 base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_; | |
| 198 | |
| 199 // Default LoginDisplayHost. | |
| 200 static LoginDisplayHost* default_host_; | |
| 201 | |
| 202 // Sign in screen controller. | |
| 203 scoped_ptr<ExistingUserController> sign_in_controller_; | |
| 204 | |
| 205 // OOBE and some screens (camera, recovery) controller. | |
| 206 scoped_ptr<WizardController> wizard_controller_; | |
| 207 | |
| 208 // App launch controller. | |
| 209 scoped_ptr<AppLaunchController> app_launch_controller_; | |
| 210 | |
| 211 // Demo app launcher. | |
| 212 scoped_ptr<DemoAppLauncher> demo_app_launcher_; | |
| 213 | |
| 214 // The controller driving the auto-enrollment check. | |
| 215 scoped_ptr<AutoEnrollmentController> auto_enrollment_controller_; | |
| 216 | |
| 217 // Subscription for progress callbacks from |auto_enrollement_controller_|. | |
| 218 scoped_ptr<AutoEnrollmentController::ProgressCallbackList::Subscription> | |
| 219 auto_enrollment_progress_subscription_; | |
| 220 | |
| 221 // Has ShutdownDisplayHost() already been called? Used to avoid posting our | |
| 222 // own deletion to the message loop twice if the user logs out while we're | |
| 223 // still in the process of cleaning up after login (http://crbug.com/134463). | |
| 224 bool shutting_down_; | |
| 225 | |
| 226 // Whether progress bar is shown on the OOBE page. | |
| 227 bool oobe_progress_bar_visible_; | |
| 228 | |
| 229 // True if session start is in progress. | |
| 230 bool session_starting_; | |
| 231 | |
| 232 // Container of the screen we are displaying. | |
| 233 views::Widget* login_window_; | |
| 234 | |
| 235 // Container of the view we are displaying. | |
| 236 WebUILoginView* login_view_; | |
| 237 | |
| 238 // Login display we are using. | |
| 239 WebUILoginDisplay* webui_login_display_; | |
| 240 | |
| 241 // True if the login display is the current screen. | |
| 242 bool is_showing_login_; | |
| 243 | |
| 244 // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been | |
| 245 // received. | |
| 246 bool is_wallpaper_loaded_; | |
| 247 | |
| 248 // Stores status area current visibility to be applied once login WebUI | |
| 249 // is shown. | |
| 250 bool status_area_saved_visibility_; | |
| 251 | |
| 252 // If true, WebUI is initialized in a hidden state and shown after the | |
| 253 // wallpaper animation is finished (when it is enabled) or the user pods have | |
| 254 // been loaded (otherwise). | |
| 255 // By default is true. Could be used to tune performance if needed. | |
| 256 bool initialize_webui_hidden_; | |
| 257 | |
| 258 // True if WebUI is initialized in hidden state and we're waiting for | |
| 259 // wallpaper load animation to finish. | |
| 260 bool waiting_for_wallpaper_load_; | |
| 261 | |
| 262 // True if WebUI is initialized in hidden state and we're waiting for user | |
| 263 // pods to load. | |
| 264 bool waiting_for_user_pods_; | |
| 265 | |
| 266 // How many times renderer has crashed. | |
| 267 int crash_count_; | |
| 268 | |
| 269 // Way to restore if renderer have crashed. | |
| 270 RestorePath restore_path_; | |
| 271 | |
| 272 // Stored parameters for StartWizard, required to restore in case of crash. | |
| 273 std::string wizard_first_screen_name_; | |
| 274 scoped_ptr<base::DictionaryValue> wizard_screen_parameters_; | |
| 275 | |
| 276 // Called before host deletion. | |
| 277 base::Closure completion_callback_; | |
| 278 | |
| 279 // Active instance of authentication prewarmer. | |
| 280 scoped_ptr<AuthPrewarmer> auth_prewarmer_; | |
| 281 | |
| 282 // A focus ring controller to draw focus ring around view for keyboard | |
| 283 // driven oobe. | |
| 284 scoped_ptr<FocusRingController> focus_ring_controller_; | |
| 285 | |
| 286 // Handles special keys for keyboard driven oobe. | |
| 287 scoped_ptr<KeyboardDrivenOobeKeyHandler> keyboard_driven_oobe_key_handler_; | |
| 288 | |
| 289 FinalizeAnimationType finalize_animation_type_; | |
| 290 | |
| 291 base::WeakPtrFactory<LoginDisplayHostImpl> animation_weak_ptr_factory_; | |
| 292 | |
| 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_; | |
| 296 | |
| 297 // True when request to play startup sound was sent to | |
| 298 // SoundsManager. | |
| 299 bool startup_sound_played_; | |
| 300 | |
| 301 // When true, startup sound should be played only when spoken | |
| 302 // feedback is enabled. Otherwise, startup sound should be played | |
| 303 // in any case. | |
| 304 bool startup_sound_honors_spoken_feedback_; | |
| 305 | |
| 306 // True is subscribed as keyboard controller observer. | |
| 307 bool is_observing_keyboard_; | |
| 308 | |
| 309 // The bounds of the virtual keyboard. | |
| 310 gfx::Rect keyboard_bounds_; | |
| 311 | |
| 312 DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl); | |
| 313 }; | |
| 314 | |
| 315 } // namespace chromeos | |
| 316 | |
| 317 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_ | |
| OLD | NEW |