• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/observer_list.h"
15 #include "chrome/browser/chromeos/login/ui/oobe_display.h"
16 #include "chrome/browser/ui/webui/chromeos/login/core_oobe_handler.h"
17 #include "content/public/browser/web_ui_controller.h"
18 
19 namespace base {
20 class DictionaryValue;
21 }  // namespace base
22 
23 namespace chromeos {
24 class AppLaunchSplashScreenActor;
25 class BaseScreenHandler;
26 class ControllerPairingScreenActor;
27 class ErrorScreenHandler;
28 class HostPairingScreenActor;
29 class KioskAppMenuHandler;
30 class KioskEnableScreenActor;
31 class LoginScreenContext;
32 class NativeWindowDelegate;
33 class NetworkDropdownHandler;
34 class NetworkStateInformer;
35 class GaiaScreenHandler;
36 class SigninScreenHandler;
37 class SigninScreenHandlerDelegate;
38 class UpdateScreenHandler;
39 
40 // A custom WebUI that defines datasource for out-of-box-experience (OOBE) UI:
41 // - welcome screen (setup language/keyboard/network).
42 // - eula screen (CrOS (+ OEM) EULA content/TPM password/crash reporting).
43 // - update screen.
44 class OobeUI : public OobeDisplay,
45                public content::WebUIController,
46                public CoreOobeHandler::Delegate {
47  public:
48   class Observer {
49    public:
~Observer()50     virtual ~Observer() {}
51     virtual void OnCurrentScreenChanged(
52         Screen current_screen, Screen new_screen) = 0;
53   };
54 
55   // List of known types of OobeUI. Type added as path in chrome://oobe url, for
56   // example chrome://oobe/user-adding.
57   static const char kOobeDisplay[];
58   static const char kLoginDisplay[];
59   static const char kLockDisplay[];
60   static const char kUserAddingDisplay[];
61   static const char kAppLaunchSplashDisplay[];
62 
63   // JS oobe/login screens names.
64   static const char kScreenOobeHIDDetection[];
65   static const char kScreenOobeNetwork[];
66   static const char kScreenOobeEula[];
67   static const char kScreenOobeUpdate[];
68   static const char kScreenOobeEnrollment[];
69   static const char kScreenOobeReset[];
70   static const char kScreenGaiaSignin[];
71   static const char kScreenAccountPicker[];
72   static const char kScreenKioskAutolaunch[];
73   static const char kScreenKioskEnable[];
74   static const char kScreenErrorMessage[];
75   static const char kScreenUserImagePicker[];
76   static const char kScreenTpmError[];
77   static const char kScreenPasswordChanged[];
78   static const char kScreenSupervisedUserCreationFlow[];
79   static const char kScreenTermsOfService[];
80   static const char kScreenWrongHWID[];
81   static const char kScreenAutoEnrollmentCheck[];
82   static const char kScreenAppLaunchSplash[];
83   static const char kScreenConfirmPassword[];
84   static const char kScreenFatalError[];
85   static const char kScreenHIDDetection[];
86   static const char kScreenControllerPairing[];
87   static const char kScreenHostPairing[];
88 
89   OobeUI(content::WebUI* web_ui, const GURL& url);
90   virtual ~OobeUI();
91 
92   // OobeDisplay implementation:
93   virtual CoreOobeActor* GetCoreOobeActor() OVERRIDE;
94   virtual UpdateScreenActor* GetUpdateScreenActor() OVERRIDE;
95   virtual NetworkScreenActor* GetNetworkScreenActor() OVERRIDE;
96   virtual EulaScreenActor* GetEulaScreenActor() OVERRIDE;
97   virtual EnrollmentScreenActor* GetEnrollmentScreenActor() OVERRIDE;
98   virtual ResetScreenActor* GetResetScreenActor() OVERRIDE;
99   virtual KioskAutolaunchScreenActor* GetKioskAutolaunchScreenActor() OVERRIDE;
100   virtual KioskEnableScreenActor* GetKioskEnableScreenActor() OVERRIDE;
101   virtual TermsOfServiceScreenActor*
102       GetTermsOfServiceScreenActor() OVERRIDE;
103   virtual UserImageScreenActor* GetUserImageScreenActor() OVERRIDE;
104   virtual ErrorScreenActor* GetErrorScreenActor() OVERRIDE;
105   virtual WrongHWIDScreenActor* GetWrongHWIDScreenActor() OVERRIDE;
106   virtual AutoEnrollmentCheckScreenActor*
107       GetAutoEnrollmentCheckScreenActor() OVERRIDE;
108   virtual SupervisedUserCreationScreenHandler*
109       GetSupervisedUserCreationScreenActor() OVERRIDE;
110   virtual AppLaunchSplashScreenActor*
111       GetAppLaunchSplashScreenActor() OVERRIDE;
112   virtual bool IsJSReady(const base::Closure& display_is_ready_callback)
113       OVERRIDE;
114   virtual HIDDetectionScreenActor* GetHIDDetectionScreenActor() OVERRIDE;
115   virtual ControllerPairingScreenActor* GetControllerPairingScreenActor()
116       OVERRIDE;
117   virtual HostPairingScreenActor* GetHostPairingScreenActor() OVERRIDE;
118 
119   // Collects localized strings from the owned handlers.
120   void GetLocalizedStrings(base::DictionaryValue* localized_strings);
121 
122   // Initializes the handlers.
123   void InitializeHandlers();
124 
125   // Invoked after the async assets load. The screen handler that has the same
126   // async assets load id will be initialized.
127   void OnScreenAssetsLoaded(const std::string& async_assets_load_id);
128 
129   // Shows or hides OOBE UI elements.
130   void ShowOobeUI(bool show);
131 
132   // TODO(rkc): Create a separate retail mode login UI and move this method
133   // there - see crbug.com/157671.
134   // Shows a login spinner for retail mode logins.
135   void ShowRetailModeLoginSpinner();
136 
137   // Shows the signin screen.
138   void ShowSigninScreen(const LoginScreenContext& context,
139                         SigninScreenHandlerDelegate* delegate,
140                         NativeWindowDelegate* native_window_delegate);
141 
142   // Resets the delegate set in ShowSigninScreen.
143   void ResetSigninScreenHandlerDelegate();
144 
145   // Add and remove observers for screen change events.
146   void AddObserver(Observer* observer);
147   void RemoveObserver(Observer* observer);
148 
current_screen()149   Screen current_screen() const { return current_screen_; }
150 
previous_screen()151   Screen previous_screen() const { return previous_screen_; }
152 
display_type()153   const std::string& display_type() const { return display_type_; }
154 
155   const std::string& GetScreenName(Screen screen) const;
156 
signin_screen_handler_for_test()157   SigninScreenHandler* signin_screen_handler_for_test() {
158     return signin_screen_handler_;
159   }
160 
161  private:
162   // Initializes |screen_ids_| and |screen_names_| structures.
163   void InitializeScreenMaps();
164 
165   void AddScreenHandler(BaseScreenHandler* handler);
166 
167   // CoreOobeHandler::Delegate implementation:
168   virtual void OnCurrentScreenChanged(const std::string& screen) OVERRIDE;
169 
170   // Type of UI.
171   std::string display_type_;
172 
173   // Reference to NetworkStateInformer that handles changes in network
174   // state.
175   scoped_refptr<NetworkStateInformer> network_state_informer_;
176 
177   // Reference to CoreOobeHandler that handles common requests of Oobe page.
178   CoreOobeHandler* core_handler_;
179 
180   // Reference to NetworkDropdownHandler that handles interaction with
181   // network dropdown.
182   NetworkDropdownHandler* network_dropdown_handler_;
183 
184   // Screens actors. Note, OobeUI owns them via |handlers_|, not directly here.
185   UpdateScreenHandler* update_screen_handler_;
186   NetworkScreenActor* network_screen_actor_;
187   EulaScreenActor* eula_screen_actor_;
188   EnrollmentScreenActor* enrollment_screen_actor_;
189   HIDDetectionScreenActor* hid_detection_screen_actor_;
190   ResetScreenActor* reset_screen_actor_;
191   KioskAutolaunchScreenActor* autolaunch_screen_actor_;
192   KioskEnableScreenActor* kiosk_enable_screen_actor_;
193   WrongHWIDScreenActor* wrong_hwid_screen_actor_;
194   AutoEnrollmentCheckScreenActor* auto_enrollment_check_screen_actor_;
195   SupervisedUserCreationScreenHandler*
196       supervised_user_creation_screen_actor_;
197   AppLaunchSplashScreenActor* app_launch_splash_screen_actor_;
198   ControllerPairingScreenActor* controller_pairing_screen_actor_;
199   HostPairingScreenActor* host_pairing_screen_actor_;
200 
201   // Reference to ErrorScreenHandler that handles error screen
202   // requests and forward calls from native code to JS side.
203   ErrorScreenHandler* error_screen_handler_;
204 
205   // Reference to GaiaScreenHandler that handles gaia screen requests and
206   // forwards calls from native code to JS side.
207   GaiaScreenHandler* gaia_screen_handler_;
208 
209   // Reference to SigninScreenHandler that handles sign-in screen requests and
210   // forwards calls from native code to JS side.
211   SigninScreenHandler* signin_screen_handler_;
212 
213   TermsOfServiceScreenActor* terms_of_service_screen_actor_;
214   UserImageScreenActor* user_image_screen_actor_;
215 
216   std::vector<BaseScreenHandler*> handlers_;  // Non-owning pointers.
217 
218   KioskAppMenuHandler* kiosk_app_menu_handler_;  // Non-owning pointers.
219 
220   // Id of the current oobe/login screen.
221   Screen current_screen_;
222 
223   // Id of the previous oobe/login screen.
224   Screen previous_screen_;
225 
226   // Maps JS screen names to screen ids.
227   std::map<std::string, Screen> screen_ids_;
228 
229   // Maps screen ids to JS screen names.
230   std::vector<std::string> screen_names_;
231 
232   // Flag that indicates whether JS part is fully loaded and ready to accept
233   // calls.
234   bool ready_;
235 
236   // Callbacks to notify when JS part is fully loaded and ready to accept calls.
237   std::vector<base::Closure> ready_callbacks_;
238 
239   // List of registered observers.
240   ObserverList<Observer> observer_list_;
241 
242   DISALLOW_COPY_AND_ASSIGN(OobeUI);
243 };
244 
245 }  // namespace chromeos
246 
247 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_
248