Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / ui / login_display_host_impl.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_HOST_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_HOST_IMPL_H_
7
8 #include <string>
9 #include <vector>
10
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"
30
31 #if !defined(USE_ATHENA)
32 #include "ash/shell_delegate.h"
33 #endif
34
35 class PrefService;
36
37 namespace content {
38 class RenderFrameHost;
39 class WebContents;
40 }
41
42 namespace chromeos {
43
44 class DemoAppLauncher;
45 class FocusRingController;
46 class OobeUI;
47 class WebUILoginDisplay;
48 class WebUILoginView;
49
50 #if !defined(USE_ATHENA)
51 class KeyboardDrivenOobeKeyHandler;
52 #endif
53
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,
63 #endif
64                              public keyboard::KeyboardControllerObserver,
65                              public gfx::DisplayObserver,
66                              public views::WidgetRemovalsObserver {
67  public:
68   explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds);
69   virtual ~LoginDisplayHostImpl();
70
71   // Returns the default LoginDisplayHost instance if it has been created.
72   static LoginDisplayHost* default_host() {
73     return default_host_;
74   }
75
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;
101
102   // Creates WizardController instance.
103   WizardController* CreateWizardController();
104
105   // Called when the first browser window is created, but before it's shown.
106   void OnBrowserCreated();
107
108   // Returns instance of the OOBE WebUI.
109   OobeUI* GetOobeUI() const;
110
111   const gfx::Rect& background_bounds() const { return background_bounds_; }
112
113   // Trace id for ShowLoginWebUI event (since there exists at most one login
114   // WebUI at a time).
115   static const int kShowLoginWebUIid;
116
117   views::Widget* login_window_for_test() { return login_window_; }
118
119  protected:
120   // content::NotificationObserver implementation:
121   virtual void Observe(int type,
122                        const content::NotificationSource& source,
123                        const content::NotificationDetails& details) override;
124
125   // Overridden from content::WebContentsObserver:
126   virtual void RenderProcessGone(base::TerminationStatus status) override;
127
128   // Overridden from chromeos::SessionManagerClient::Observer:
129   virtual void EmitLoginPromptVisibleCalled() override;
130
131   // Overridden from chromeos::CrasAudioHandler::AudioObserver:
132   virtual void OnActiveOutputNodeChanged() override;
133
134 #if !defined(USE_ATHENA)
135   // Overridden from ash::KeyboardStateObserver:
136   virtual void OnVirtualKeyboardStateChanged(bool activated) override;
137 #endif
138
139   // Overridden from keyboard::KeyboardControllerObserver:
140   virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override;
141
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;
147
148   // Overriden from views::WidgetRemovalsObserver:
149   virtual void OnWillRemoveView(views::Widget* widget,
150                                 views::View* view) override;
151
152  private:
153   // Way to restore if renderer have crashed.
154   enum RestorePath {
155     RESTORE_UNKNOWN,
156     RESTORE_WIZARD,
157     RESTORE_SIGN_IN,
158     RESTORE_ADD_USER_INTO_SESSION,
159   };
160
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.
167   };
168
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);
172
173   // Schedules workspace transition animation.
174   void ScheduleWorkspaceAnimation();
175
176   // Schedules fade out animation.
177   void ScheduleFadeOutAnimation();
178
179   // Progress callback registered with |auto_enrollment_controller_|.
180   void OnAutoEnrollmentProgress(policy::AutoEnrollmentState state);
181
182   // Loads given URL. Creates WebUILoginView if needed.
183   void LoadURL(const GURL& url);
184
185   // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
186   void ShowWebUI();
187
188   // Starts postponed WebUI (OOBE/sign in) if it was waiting for
189   // wallpaper animation end.
190   void StartPostponedWebUI();
191
192   // Initializes |login_window_| and |login_view_| fields if needed.
193   void InitLoginWindowAndView();
194
195   // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
196   void ResetLoginWindowAndView();
197
198   // Deletes |auth_prewarmer_|.
199   void OnAuthPrewarmDone();
200
201   // Toggles OOBE progress bar visibility, the bar is hidden by default.
202   void SetOobeProgressBarVisible(bool visible);
203
204   // Tries to play startup sound. If sound can't be played right now,
205   // for instance, because cras server is not initialized, playback
206   // will be delayed.
207   void TryToPlayStartupSound();
208
209   // Called when login-prompt-visible signal is caught.
210   void OnLoginPromptVisible();
211
212   // Used to calculate position of the screens and background.
213   gfx::Rect background_bounds_;
214
215   content::NotificationRegistrar registrar_;
216
217   base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_;
218
219   // Default LoginDisplayHost.
220   static LoginDisplayHost* default_host_;
221
222   // The controller driving the auto-enrollment check.
223   scoped_ptr<AutoEnrollmentController> auto_enrollment_controller_;
224
225   // Subscription for progress callbacks from |auto_enrollement_controller_|.
226   scoped_ptr<AutoEnrollmentController::ProgressCallbackList::Subscription>
227       auto_enrollment_progress_subscription_;
228
229   // Sign in screen controller.
230   scoped_ptr<ExistingUserController> sign_in_controller_;
231
232   // OOBE and some screens (camera, recovery) controller.
233   scoped_ptr<WizardController> wizard_controller_;
234
235   // App launch controller.
236   scoped_ptr<AppLaunchController> app_launch_controller_;
237
238   // Demo app launcher.
239   scoped_ptr<DemoAppLauncher> demo_app_launcher_;
240
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).
244   bool shutting_down_;
245
246   // Whether progress bar is shown on the OOBE page.
247   bool oobe_progress_bar_visible_;
248
249   // True if session start is in progress.
250   bool session_starting_;
251
252   // Container of the screen we are displaying.
253   views::Widget* login_window_;
254
255   // Container of the view we are displaying.
256   WebUILoginView* login_view_;
257
258   // Login display we are using.
259   WebUILoginDisplay* webui_login_display_;
260
261   // True if the login display is the current screen.
262   bool is_showing_login_;
263
264   // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
265   // received.
266   bool is_wallpaper_loaded_;
267
268   // Stores status area current visibility to be applied once login WebUI
269   // is shown.
270   bool status_area_saved_visibility_;
271
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_;
277
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_;
281
282   // True if WebUI is initialized in hidden state and we're waiting for user
283   // pods to load.
284   bool waiting_for_user_pods_;
285
286   // How many times renderer has crashed.
287   int crash_count_;
288
289   // Way to restore if renderer have crashed.
290   RestorePath restore_path_;
291
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_;
295
296   // Called before host deletion.
297   base::Closure completion_callback_;
298
299   // Active instance of authentication prewarmer.
300   scoped_ptr<AuthPrewarmer> auth_prewarmer_;
301
302   // A focus ring controller to draw focus ring around view for keyboard
303   // driven oobe.
304   scoped_ptr<FocusRingController> focus_ring_controller_;
305
306 #if !defined(USE_ATHENA)
307   // Handles special keys for keyboard driven oobe.
308   scoped_ptr<KeyboardDrivenOobeKeyHandler> keyboard_driven_oobe_key_handler_;
309 #endif
310
311   FinalizeAnimationType finalize_animation_type_;
312
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_;
316
317   // True when request to play startup sound was sent to
318   // SoundsManager.
319   bool startup_sound_played_;
320
321   // When true, startup sound should be played only when spoken
322   // feedback is enabled.  Otherwise, startup sound should be played
323   // in any case.
324   bool startup_sound_honors_spoken_feedback_;
325
326   // True is subscribed as keyboard controller observer.
327   bool is_observing_keyboard_;
328
329   // The bounds of the virtual keyboard.
330   gfx::Rect keyboard_bounds_;
331
332 #if defined(USE_ATHENA)
333   scoped_ptr<aura::Window> login_screen_container_;
334 #endif
335
336   base::WeakPtrFactory<LoginDisplayHostImpl> animation_weak_ptr_factory_;
337
338   DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl);
339 };
340
341 }  // namespace chromeos
342
343 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_HOST_IMPL_H_