Home | History | Annotate | Download | only in login
      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/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 CoreOobeHandler;
     27 class ErrorScreenHandler;
     28 class KioskAppMenuHandler;
     29 class KioskEnableScreenActor;
     30 class LoginScreenContext;
     31 class NativeWindowDelegate;
     32 class NetworkDropdownHandler;
     33 class NetworkStateInformer;
     34 class GaiaScreenHandler;
     35 class SigninScreenHandler;
     36 class SigninScreenHandlerDelegate;
     37 class UpdateScreenHandler;
     38 
     39 // A custom WebUI that defines datasource for out-of-box-experience (OOBE) UI:
     40 // - welcome screen (setup language/keyboard/network).
     41 // - eula screen (CrOS (+ OEM) EULA content/TPM password/crash reporting).
     42 // - update screen.
     43 class OobeUI : public OobeDisplay,
     44                public content::WebUIController,
     45                public CoreOobeHandler::Delegate {
     46  public:
     47   class Observer {
     48    public:
     49     virtual ~Observer() {}
     50     virtual void OnCurrentScreenChanged(
     51         Screen current_screen, Screen new_screen) = 0;
     52   };
     53 
     54   // JS oobe/login screens names.
     55   static const char kScreenOobeNetwork[];
     56   static const char kScreenOobeEula[];
     57   static const char kScreenOobeUpdate[];
     58   static const char kScreenOobeEnrollment[];
     59   static const char kScreenGaiaSignin[];
     60   static const char kScreenAccountPicker[];
     61   static const char kScreenKioskAutolaunch[];
     62   static const char kScreenKioskEnable[];
     63   static const char kScreenErrorMessage[];
     64   static const char kScreenUserImagePicker[];
     65   static const char kScreenTpmError[];
     66   static const char kScreenPasswordChanged[];
     67   static const char kScreenManagedUserCreationFlow[];
     68   static const char kScreenTermsOfService[];
     69   static const char kScreenWrongHWID[];
     70   static const char kScreenAppLaunchSplash[];
     71   static const char kScreenConfirmPassword[];
     72   static const char kScreenMessageBox[];
     73 
     74   OobeUI(content::WebUI* web_ui, const GURL& url);
     75   virtual ~OobeUI();
     76 
     77   // OobeDisplay implementation:
     78   virtual void ShowScreen(WizardScreen* screen) OVERRIDE;
     79   virtual void HideScreen(WizardScreen* screen) OVERRIDE;
     80   virtual UpdateScreenActor* GetUpdateScreenActor() OVERRIDE;
     81   virtual NetworkScreenActor* GetNetworkScreenActor() OVERRIDE;
     82   virtual EulaScreenActor* GetEulaScreenActor() OVERRIDE;
     83   virtual EnrollmentScreenActor* GetEnrollmentScreenActor() OVERRIDE;
     84   virtual ResetScreenActor* GetResetScreenActor() OVERRIDE;
     85   virtual KioskAutolaunchScreenActor* GetKioskAutolaunchScreenActor() OVERRIDE;
     86   virtual KioskEnableScreenActor* GetKioskEnableScreenActor() OVERRIDE;
     87   virtual TermsOfServiceScreenActor*
     88       GetTermsOfServiceScreenActor() OVERRIDE;
     89   virtual UserImageScreenActor* GetUserImageScreenActor() OVERRIDE;
     90   virtual ErrorScreenActor* GetErrorScreenActor() OVERRIDE;
     91   virtual WrongHWIDScreenActor* GetWrongHWIDScreenActor() OVERRIDE;
     92   virtual LocallyManagedUserCreationScreenHandler*
     93       GetLocallyManagedUserCreationScreenActor() OVERRIDE;
     94   virtual AppLaunchSplashScreenActor*
     95       GetAppLaunchSplashScreenActor() OVERRIDE;
     96   virtual bool IsJSReady(const base::Closure& display_is_ready_callback)
     97       OVERRIDE;
     98 
     99   // Collects localized strings from the owned handlers.
    100   void GetLocalizedStrings(base::DictionaryValue* localized_strings);
    101 
    102   // Initializes the handlers.
    103   void InitializeHandlers();
    104 
    105   // Invoked after the async assets load. The screen handler that has the same
    106   // async assets load id will be initialized.
    107   void OnScreenAssetsLoaded(const std::string& async_assets_load_id);
    108 
    109   // Shows or hides OOBE UI elements.
    110   void ShowOobeUI(bool show);
    111 
    112   // TODO(rkc): Create a separate retail mode login UI and move this method
    113   // there - see crbug.com/157671.
    114   // Shows a login spinner for retail mode logins.
    115   void ShowRetailModeLoginSpinner();
    116 
    117   // Shows the signin screen.
    118   void ShowSigninScreen(const LoginScreenContext& context,
    119                         SigninScreenHandlerDelegate* delegate,
    120                         NativeWindowDelegate* native_window_delegate);
    121 
    122   // Shows the kiosk splash screen.
    123   void ShowAppLaunchSplashScreen();
    124 
    125   // Resets the delegate set in ShowSigninScreen.
    126   void ResetSigninScreenHandlerDelegate();
    127 
    128   // Add and remove observers for screen change events.
    129   void AddObserver(Observer* observer);
    130   void RemoveObserver(Observer* observer);
    131 
    132   Screen current_screen() const { return current_screen_; }
    133 
    134   const std::string& GetScreenName(Screen screen) const;
    135 
    136   SigninScreenHandler* signin_screen_handler_for_test() {
    137     return signin_screen_handler_;
    138   }
    139 
    140  private:
    141   // Initializes |screen_ids_| and |screen_names_| structures.
    142   void InitializeScreenMaps();
    143 
    144   void AddScreenHandler(BaseScreenHandler* handler);
    145 
    146   // CoreOobeHandler::Delegate implementation:
    147   virtual void OnCurrentScreenChanged(const std::string& screen) OVERRIDE;
    148 
    149   // Type of UI.
    150   std::string display_type_;
    151 
    152   // Reference to NetworkStateInformer that handles changes in network
    153   // state.
    154   scoped_refptr<NetworkStateInformer> network_state_informer_;
    155 
    156   // Reference to CoreOobeHandler that handles common requests of Oobe page.
    157   CoreOobeHandler* core_handler_;
    158 
    159   // Reference to NetworkDropdownHandler that handles interaction with
    160   // network dropdown.
    161   NetworkDropdownHandler* network_dropdown_handler_;
    162 
    163   // Screens actors. Note, OobeUI owns them via |handlers_|, not directly here.
    164   UpdateScreenHandler* update_screen_handler_;
    165   NetworkScreenActor* network_screen_actor_;
    166   EulaScreenActor* eula_screen_actor_;
    167   EnrollmentScreenActor* enrollment_screen_actor_;
    168   ResetScreenActor* reset_screen_actor_;
    169   KioskAutolaunchScreenActor* autolaunch_screen_actor_;
    170   KioskEnableScreenActor* kiosk_enable_screen_actor_;
    171   WrongHWIDScreenActor* wrong_hwid_screen_actor_;
    172   LocallyManagedUserCreationScreenHandler*
    173       locally_managed_user_creation_screen_actor_;
    174   AppLaunchSplashScreenActor* app_launch_splash_screen_actor_;
    175 
    176   // Reference to ErrorScreenHandler that handles error screen
    177   // requests and forward calls from native code to JS side.
    178   ErrorScreenHandler* error_screen_handler_;
    179 
    180   // Reference to GaiaScreenHandler that handles gaia screen requests and
    181   // forwards calls from native code to JS side.
    182   GaiaScreenHandler* gaia_screen_handler_;
    183 
    184   // Reference to SigninScreenHandler that handles sign-in screen requests and
    185   // forwards calls from native code to JS side.
    186   SigninScreenHandler* signin_screen_handler_;
    187 
    188   TermsOfServiceScreenActor* terms_of_service_screen_actor_;
    189   UserImageScreenActor* user_image_screen_actor_;
    190 
    191   std::vector<BaseScreenHandler*> handlers_;  // Non-owning pointers.
    192 
    193   KioskAppMenuHandler* kiosk_app_menu_handler_;  // Non-owning pointers.
    194 
    195   // Id of the current oobe/login screen.
    196   Screen current_screen_;
    197 
    198   // Maps JS screen names to screen ids.
    199   std::map<std::string, Screen> screen_ids_;
    200 
    201   // Maps screen ids to JS screen names.
    202   std::vector<std::string> screen_names_;
    203 
    204   // Flag that indicates whether JS part is fully loaded and ready to accept
    205   // calls.
    206   bool ready_;
    207 
    208   // Callbacks to notify when JS part is fully loaded and ready to accept calls.
    209   std::vector<base::Closure> ready_callbacks_;
    210 
    211   // List of registered observers.
    212   ObserverList<Observer> observer_list_;
    213 
    214   DISALLOW_COPY_AND_ASSIGN(OobeUI);
    215 };
    216 
    217 }  // namespace chromeos
    218 
    219 #endif  // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_OOBE_UI_H_
    220