Home | History | Annotate | Download | only in login
      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 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
      6 
      7 #include "base/command_line.h"
      8 #include "base/logging.h"
      9 #include "base/strings/stringprintf.h"
     10 #include "base/values.h"
     11 #include "chrome/browser/browser_process.h"
     12 #include "chrome/browser/browser_process_platform_part.h"
     13 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
     14 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen_actor.h"
     15 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen_actor.h"
     16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
     17 #include "chrome/browser/chromeos/policy/consumer_management_service.h"
     18 #include "chrome/browser/chromeos/system/input_device_settings.h"
     19 #include "chrome/browser/extensions/signin/gaia_auth_extension_loader.h"
     20 #include "chrome/browser/profiles/profile.h"
     21 #include "chrome/browser/ui/webui/about_ui.h"
     22 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handler.h"
     23 #include "chrome/browser/ui/webui/chromeos/login/auto_enrollment_check_screen_handler.h"
     24 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
     25 #include "chrome/browser/ui/webui/chromeos/login/controller_pairing_screen_handler.h"
     26 #include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h"
     27 #include "chrome/browser/ui/webui/chromeos/login/error_screen_handler.h"
     28 #include "chrome/browser/ui/webui/chromeos/login/eula_screen_handler.h"
     29 #include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
     30 #include "chrome/browser/ui/webui/chromeos/login/hid_detection_screen_handler.h"
     31 #include "chrome/browser/ui/webui/chromeos/login/host_pairing_screen_handler.h"
     32 #include "chrome/browser/ui/webui/chromeos/login/kiosk_app_menu_handler.h"
     33 #include "chrome/browser/ui/webui/chromeos/login/kiosk_autolaunch_screen_handler.h"
     34 #include "chrome/browser/ui/webui/chromeos/login/kiosk_enable_screen_handler.h"
     35 #include "chrome/browser/ui/webui/chromeos/login/network_dropdown_handler.h"
     36 #include "chrome/browser/ui/webui/chromeos/login/network_screen_handler.h"
     37 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
     38 #include "chrome/browser/ui/webui/chromeos/login/reset_screen_handler.h"
     39 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
     40 #include "chrome/browser/ui/webui/chromeos/login/supervised_user_creation_screen_handler.h"
     41 #include "chrome/browser/ui/webui/chromeos/login/terms_of_service_screen_handler.h"
     42 #include "chrome/browser/ui/webui/chromeos/login/update_screen_handler.h"
     43 #include "chrome/browser/ui/webui/chromeos/login/user_image_screen_handler.h"
     44 #include "chrome/browser/ui/webui/chromeos/login/wrong_hwid_screen_handler.h"
     45 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
     46 #include "chrome/browser/ui/webui/theme_source.h"
     47 #include "chrome/common/chrome_constants.h"
     48 #include "chrome/common/url_constants.h"
     49 #include "chromeos/chromeos_switches.h"
     50 #include "content/public/browser/web_ui.h"
     51 #include "content/public/browser/web_ui_data_source.h"
     52 #include "grit/browser_resources.h"
     53 #include "ui/base/resource/resource_bundle.h"
     54 #include "ui/base/webui/web_ui_util.h"
     55 
     56 namespace chromeos {
     57 
     58 namespace {
     59 
     60 const char* kKnownDisplayTypes[] = {
     61   OobeUI::kOobeDisplay,
     62   OobeUI::kLoginDisplay,
     63   OobeUI::kLockDisplay,
     64   OobeUI::kUserAddingDisplay,
     65   OobeUI::kAppLaunchSplashDisplay
     66 };
     67 
     68 const char kStringsJSPath[] = "strings.js";
     69 const char kLoginJSPath[] = "login.js";
     70 const char kOobeJSPath[] = "oobe.js";
     71 const char kKeyboardUtilsJSPath[] = "keyboard_utils.js";
     72 const char kDemoUserLoginJSPath[] = "demo_user_login.js";
     73 
     74 // Paths for deferred resource loading.
     75 const char kEnrollmentHTMLPath[] = "enrollment.html";
     76 const char kEnrollmentCSSPath[] = "enrollment.css";
     77 const char kEnrollmentJSPath[] = "enrollment.js";
     78 
     79 // Creates a WebUIDataSource for chrome://oobe
     80 content::WebUIDataSource* CreateOobeUIDataSource(
     81     const base::DictionaryValue& localized_strings,
     82     const std::string& display_type) {
     83   content::WebUIDataSource* source =
     84       content::WebUIDataSource::Create(chrome::kChromeUIOobeHost);
     85   source->SetUseJsonJSFormatV2();
     86   source->AddLocalizedStrings(localized_strings);
     87   source->SetJsonPath(kStringsJSPath);
     88 
     89   if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) {
     90     source->SetDefaultResource(IDR_DEMO_USER_LOGIN_HTML);
     91     source->AddResourcePath(kDemoUserLoginJSPath, IDR_DEMO_USER_LOGIN_JS);
     92     return source;
     93   }
     94   if (display_type == OobeUI::kOobeDisplay) {
     95     source->SetDefaultResource(IDR_OOBE_HTML);
     96     source->AddResourcePath(kOobeJSPath, IDR_OOBE_JS);
     97   } else {
     98     source->SetDefaultResource(IDR_LOGIN_HTML);
     99     source->AddResourcePath(kLoginJSPath, IDR_LOGIN_JS);
    100   }
    101   source->AddResourcePath(kKeyboardUtilsJSPath, IDR_KEYBOARD_UTILS_JS);
    102   source->OverrideContentSecurityPolicyFrameSrc(
    103       base::StringPrintf(
    104           "frame-src chrome://terms/ %s/;",
    105           extensions::kGaiaAuthExtensionOrigin));
    106 
    107   // Serve deferred resources.
    108   source->AddResourcePath(kEnrollmentHTMLPath, IDR_OOBE_ENROLLMENT_HTML);
    109   source->AddResourcePath(kEnrollmentCSSPath, IDR_OOBE_ENROLLMENT_CSS);
    110   source->AddResourcePath(kEnrollmentJSPath, IDR_OOBE_ENROLLMENT_JS);
    111 
    112   return source;
    113 }
    114 
    115 std::string GetDisplayType(const GURL& url) {
    116   std::string path = url.path().size() ? url.path().substr(1) : "";
    117   if (std::find(kKnownDisplayTypes,
    118                 kKnownDisplayTypes + arraysize(kKnownDisplayTypes),
    119                 path) == kKnownDisplayTypes + arraysize(kKnownDisplayTypes)) {
    120     LOG(ERROR) << "Unknown display type '" << path << "'. Setting default.";
    121     return OobeUI::kLoginDisplay;
    122   }
    123   return path;
    124 }
    125 
    126 }  // namespace
    127 
    128 // static
    129 const char OobeUI::kOobeDisplay[] = "oobe";
    130 const char OobeUI::kLoginDisplay[] = "login";
    131 const char OobeUI::kLockDisplay[] = "lock";
    132 const char OobeUI::kUserAddingDisplay[] = "user-adding";
    133 const char OobeUI::kAppLaunchSplashDisplay[] = "app-launch-splash";
    134 
    135 // static
    136 const char OobeUI::kScreenOobeHIDDetection[] = "hid-detection";
    137 const char OobeUI::kScreenOobeNetwork[] = "connect";
    138 const char OobeUI::kScreenOobeEula[] = "eula";
    139 const char OobeUI::kScreenOobeUpdate[] = "update";
    140 const char OobeUI::kScreenOobeEnrollment[] = "oauth-enrollment";
    141 const char OobeUI::kScreenOobeReset[] = "reset";
    142 const char OobeUI::kScreenGaiaSignin[] = "gaia-signin";
    143 const char OobeUI::kScreenAccountPicker[] = "account-picker";
    144 const char OobeUI::kScreenKioskAutolaunch[] = "autolaunch";
    145 const char OobeUI::kScreenKioskEnable[] = "kiosk-enable";
    146 const char OobeUI::kScreenErrorMessage[] = "error-message";
    147 const char OobeUI::kScreenUserImagePicker[] = "user-image";
    148 const char OobeUI::kScreenTpmError[] = "tpm-error-message";
    149 const char OobeUI::kScreenPasswordChanged[] = "password-changed";
    150 const char OobeUI::kScreenSupervisedUserCreationFlow[] =
    151     "supervised-user-creation";
    152 const char OobeUI::kScreenTermsOfService[] = "terms-of-service";
    153 const char OobeUI::kScreenWrongHWID[] = "wrong-hwid";
    154 const char OobeUI::kScreenAutoEnrollmentCheck[] = "auto-enrollment-check";
    155 const char OobeUI::kScreenHIDDetection[] = "hid-detection";
    156 const char OobeUI::kScreenAppLaunchSplash[] = "app-launch-splash";
    157 const char OobeUI::kScreenConfirmPassword[] = "confirm-password";
    158 const char OobeUI::kScreenFatalError[] = "fatal-error";
    159 const char OobeUI::kScreenControllerPairing[] = "controller-pairing";
    160 const char OobeUI::kScreenHostPairing[] = "host-pairing";
    161 
    162 OobeUI::OobeUI(content::WebUI* web_ui, const GURL& url)
    163     : WebUIController(web_ui),
    164       core_handler_(NULL),
    165       network_dropdown_handler_(NULL),
    166       update_screen_handler_(NULL),
    167       network_screen_actor_(NULL),
    168       eula_screen_actor_(NULL),
    169       hid_detection_screen_actor_(NULL),
    170       reset_screen_actor_(NULL),
    171       autolaunch_screen_actor_(NULL),
    172       kiosk_enable_screen_actor_(NULL),
    173       wrong_hwid_screen_actor_(NULL),
    174       auto_enrollment_check_screen_actor_(NULL),
    175       supervised_user_creation_screen_actor_(NULL),
    176       error_screen_handler_(NULL),
    177       signin_screen_handler_(NULL),
    178       terms_of_service_screen_actor_(NULL),
    179       user_image_screen_actor_(NULL),
    180       kiosk_app_menu_handler_(NULL),
    181       current_screen_(SCREEN_UNKNOWN),
    182       previous_screen_(SCREEN_UNKNOWN),
    183       ready_(false) {
    184   display_type_ = GetDisplayType(url);
    185   InitializeScreenMaps();
    186 
    187   network_state_informer_ = new NetworkStateInformer();
    188   network_state_informer_->Init();
    189 
    190   core_handler_ = new CoreOobeHandler(this);
    191   AddScreenHandler(core_handler_);
    192   core_handler_->SetDelegate(this);
    193 
    194   network_dropdown_handler_ = new NetworkDropdownHandler();
    195   AddScreenHandler(network_dropdown_handler_);
    196 
    197   update_screen_handler_ = new UpdateScreenHandler();
    198   AddScreenHandler(update_screen_handler_);
    199   network_dropdown_handler_->AddObserver(update_screen_handler_);
    200 
    201   if (display_type_ == kOobeDisplay) {
    202     NetworkScreenHandler* network_screen_handler =
    203         new NetworkScreenHandler(core_handler_);
    204     network_screen_actor_ = network_screen_handler;
    205     AddScreenHandler(network_screen_handler);
    206   }
    207 
    208   EulaScreenHandler* eula_screen_handler = new EulaScreenHandler(core_handler_);
    209   eula_screen_actor_ = eula_screen_handler;
    210   AddScreenHandler(eula_screen_handler);
    211 
    212   ResetScreenHandler* reset_screen_handler = new ResetScreenHandler();
    213   reset_screen_actor_ = reset_screen_handler;
    214   AddScreenHandler(reset_screen_handler);
    215 
    216   KioskAutolaunchScreenHandler* autolaunch_screen_handler =
    217       new KioskAutolaunchScreenHandler();
    218   autolaunch_screen_actor_ = autolaunch_screen_handler;
    219   AddScreenHandler(autolaunch_screen_handler);
    220 
    221   KioskEnableScreenHandler* kiosk_enable_screen_handler =
    222       new KioskEnableScreenHandler();
    223   kiosk_enable_screen_actor_ = kiosk_enable_screen_handler;
    224   AddScreenHandler(kiosk_enable_screen_handler);
    225 
    226   SupervisedUserCreationScreenHandler* supervised_user_creation_screen_handler =
    227       new SupervisedUserCreationScreenHandler();
    228   supervised_user_creation_screen_actor_ =
    229       supervised_user_creation_screen_handler;
    230   AddScreenHandler(supervised_user_creation_screen_handler);
    231 
    232   WrongHWIDScreenHandler* wrong_hwid_screen_handler =
    233       new WrongHWIDScreenHandler();
    234   wrong_hwid_screen_actor_ = wrong_hwid_screen_handler;
    235   AddScreenHandler(wrong_hwid_screen_handler);
    236 
    237   AutoEnrollmentCheckScreenHandler* auto_enrollment_check_screen_handler =
    238       new AutoEnrollmentCheckScreenHandler();
    239   auto_enrollment_check_screen_actor_ = auto_enrollment_check_screen_handler;
    240   AddScreenHandler(auto_enrollment_check_screen_handler);
    241 
    242   HIDDetectionScreenHandler* hid_detection_screen_handler =
    243       new HIDDetectionScreenHandler(core_handler_);
    244   hid_detection_screen_actor_ = hid_detection_screen_handler;
    245   AddScreenHandler(hid_detection_screen_handler);
    246 
    247   error_screen_handler_ = new ErrorScreenHandler(network_state_informer_);
    248   AddScreenHandler(error_screen_handler_);
    249 
    250   EnrollmentScreenHandler* enrollment_screen_handler =
    251       new EnrollmentScreenHandler(network_state_informer_,
    252                                   error_screen_handler_);
    253   enrollment_screen_actor_ = enrollment_screen_handler;
    254   AddScreenHandler(enrollment_screen_handler);
    255 
    256   TermsOfServiceScreenHandler* terms_of_service_screen_handler =
    257       new TermsOfServiceScreenHandler(core_handler_);
    258   terms_of_service_screen_actor_ = terms_of_service_screen_handler;
    259   AddScreenHandler(terms_of_service_screen_handler);
    260 
    261   UserImageScreenHandler* user_image_screen_handler =
    262       new UserImageScreenHandler();
    263   user_image_screen_actor_ = user_image_screen_handler;
    264   AddScreenHandler(user_image_screen_handler);
    265 
    266   policy::ConsumerManagementService* consumer_management =
    267       g_browser_process->platform_part()->browser_policy_connector_chromeos()->
    268           GetConsumerManagementService();
    269   gaia_screen_handler_ =
    270       new GaiaScreenHandler(
    271           core_handler_, network_state_informer_, consumer_management);
    272   AddScreenHandler(gaia_screen_handler_);
    273 
    274   signin_screen_handler_ = new SigninScreenHandler(network_state_informer_,
    275                                                    error_screen_handler_,
    276                                                    core_handler_,
    277                                                    gaia_screen_handler_);
    278   AddScreenHandler(signin_screen_handler_);
    279 
    280   AppLaunchSplashScreenHandler* app_launch_splash_screen_handler =
    281       new AppLaunchSplashScreenHandler(network_state_informer_,
    282                                        error_screen_handler_);
    283   AddScreenHandler(app_launch_splash_screen_handler);
    284   app_launch_splash_screen_actor_ = app_launch_splash_screen_handler;
    285 
    286   if (display_type_ == kOobeDisplay) {
    287     ControllerPairingScreenHandler* handler =
    288         new ControllerPairingScreenHandler();
    289     controller_pairing_screen_actor_ = handler;
    290     AddScreenHandler(handler);
    291   }
    292 
    293   if (display_type_ == kOobeDisplay) {
    294     HostPairingScreenHandler* handler = new HostPairingScreenHandler();
    295     host_pairing_screen_actor_ = handler;
    296     AddScreenHandler(handler);
    297   }
    298 
    299   // Initialize KioskAppMenuHandler. Note that it is NOT a screen handler.
    300   kiosk_app_menu_handler_ = new KioskAppMenuHandler(network_state_informer_);
    301   web_ui->AddMessageHandler(kiosk_app_menu_handler_);
    302 
    303   base::DictionaryValue localized_strings;
    304   GetLocalizedStrings(&localized_strings);
    305 
    306   Profile* profile = Profile::FromWebUI(web_ui);
    307   // Set up the chrome://theme/ source, for Chrome logo.
    308   ThemeSource* theme = new ThemeSource(profile);
    309   content::URLDataSource::Add(profile, theme);
    310 
    311   // Set up the chrome://terms/ data source, for EULA content.
    312   AboutUIHTMLSource* about_source =
    313       new AboutUIHTMLSource(chrome::kChromeUITermsHost, profile);
    314   content::URLDataSource::Add(profile, about_source);
    315 
    316   // Set up the chrome://oobe/ source.
    317   content::WebUIDataSource::Add(profile,
    318                                 CreateOobeUIDataSource(localized_strings,
    319                                                        display_type_));
    320 
    321   // Set up the chrome://userimage/ source.
    322   options::UserImageSource* user_image_source =
    323       new options::UserImageSource();
    324   content::URLDataSource::Add(profile, user_image_source);
    325 }
    326 
    327 OobeUI::~OobeUI() {
    328   core_handler_->SetDelegate(NULL);
    329   network_dropdown_handler_->RemoveObserver(update_screen_handler_);
    330 }
    331 
    332 CoreOobeActor* OobeUI::GetCoreOobeActor() {
    333   return core_handler_;
    334 }
    335 
    336 UpdateScreenActor* OobeUI::GetUpdateScreenActor() {
    337   return update_screen_handler_;
    338 }
    339 
    340 NetworkScreenActor* OobeUI::GetNetworkScreenActor() {
    341   return network_screen_actor_;
    342 }
    343 
    344 EulaScreenActor* OobeUI::GetEulaScreenActor() {
    345   return eula_screen_actor_;
    346 }
    347 
    348 EnrollmentScreenActor* OobeUI::GetEnrollmentScreenActor() {
    349   return enrollment_screen_actor_;
    350 }
    351 
    352 ResetScreenActor* OobeUI::GetResetScreenActor() {
    353   return reset_screen_actor_;
    354 }
    355 
    356 KioskAutolaunchScreenActor* OobeUI::GetKioskAutolaunchScreenActor() {
    357   return autolaunch_screen_actor_;
    358 }
    359 
    360 KioskEnableScreenActor* OobeUI::GetKioskEnableScreenActor() {
    361   return kiosk_enable_screen_actor_;
    362 }
    363 
    364 TermsOfServiceScreenActor* OobeUI::GetTermsOfServiceScreenActor() {
    365   return terms_of_service_screen_actor_;
    366 }
    367 
    368 WrongHWIDScreenActor* OobeUI::GetWrongHWIDScreenActor() {
    369   return wrong_hwid_screen_actor_;
    370 }
    371 
    372 AutoEnrollmentCheckScreenActor* OobeUI::GetAutoEnrollmentCheckScreenActor() {
    373   return auto_enrollment_check_screen_actor_;
    374 }
    375 
    376 HIDDetectionScreenActor* OobeUI::GetHIDDetectionScreenActor() {
    377   return hid_detection_screen_actor_;
    378 }
    379 
    380 ControllerPairingScreenActor* OobeUI::GetControllerPairingScreenActor() {
    381   return controller_pairing_screen_actor_;
    382 }
    383 
    384 HostPairingScreenActor* OobeUI::GetHostPairingScreenActor() {
    385   return host_pairing_screen_actor_;
    386 }
    387 
    388 UserImageScreenActor* OobeUI::GetUserImageScreenActor() {
    389   return user_image_screen_actor_;
    390 }
    391 
    392 ErrorScreenActor* OobeUI::GetErrorScreenActor() {
    393   return error_screen_handler_;
    394 }
    395 
    396 SupervisedUserCreationScreenHandler*
    397     OobeUI::GetSupervisedUserCreationScreenActor() {
    398   return supervised_user_creation_screen_actor_;
    399 }
    400 
    401 AppLaunchSplashScreenActor*
    402       OobeUI::GetAppLaunchSplashScreenActor() {
    403   return app_launch_splash_screen_actor_;
    404 }
    405 
    406 void OobeUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) {
    407   // Note, handlers_[0] is a GenericHandler used by the WebUI.
    408   for (size_t i = 0; i < handlers_.size(); ++i)
    409     handlers_[i]->GetLocalizedStrings(localized_strings);
    410   webui::SetFontAndTextDirection(localized_strings);
    411   kiosk_app_menu_handler_->GetLocalizedStrings(localized_strings);
    412 
    413 #if defined(GOOGLE_CHROME_BUILD)
    414   localized_strings->SetString("buildType", "chrome");
    415 #else
    416   localized_strings->SetString("buildType", "chromium");
    417 #endif
    418 
    419   // If we're not doing boot animation then WebUI should trigger
    420   // wallpaper load on boot.
    421   if (CommandLine::ForCurrentProcess()->HasSwitch(
    422           switches::kDisableBootAnimation)) {
    423     localized_strings->SetString("bootIntoWallpaper", "on");
    424   } else {
    425     localized_strings->SetString("bootIntoWallpaper", "off");
    426   }
    427 
    428   bool keyboard_driven_oobe =
    429       system::InputDeviceSettings::Get()->ForceKeyboardDrivenUINavigation();
    430   localized_strings->SetString("highlightStrength",
    431                                keyboard_driven_oobe ? "strong" : "normal");
    432 
    433   bool new_kiosk_ui = KioskAppMenuHandler::EnableNewKioskUI();
    434   localized_strings->SetString("newKioskUI", new_kiosk_ui ? "on" : "off");
    435 }
    436 
    437 void OobeUI::InitializeScreenMaps() {
    438   screen_names_.resize(SCREEN_UNKNOWN);
    439   screen_names_[SCREEN_OOBE_HID_DETECTION] = kScreenOobeHIDDetection;
    440   screen_names_[SCREEN_OOBE_NETWORK] = kScreenOobeNetwork;
    441   screen_names_[SCREEN_OOBE_EULA] = kScreenOobeEula;
    442   screen_names_[SCREEN_OOBE_UPDATE] = kScreenOobeUpdate;
    443   screen_names_[SCREEN_OOBE_ENROLLMENT] = kScreenOobeEnrollment;
    444   screen_names_[SCREEN_OOBE_RESET] = kScreenOobeReset;
    445   screen_names_[SCREEN_GAIA_SIGNIN] = kScreenGaiaSignin;
    446   screen_names_[SCREEN_ACCOUNT_PICKER] = kScreenAccountPicker;
    447   screen_names_[SCREEN_KIOSK_AUTOLAUNCH] = kScreenKioskAutolaunch;
    448   screen_names_[SCREEN_KIOSK_ENABLE] = kScreenKioskEnable;
    449   screen_names_[SCREEN_ERROR_MESSAGE] = kScreenErrorMessage;
    450   screen_names_[SCREEN_USER_IMAGE_PICKER] = kScreenUserImagePicker;
    451   screen_names_[SCREEN_TPM_ERROR] = kScreenTpmError;
    452   screen_names_[SCREEN_PASSWORD_CHANGED] = kScreenPasswordChanged;
    453   screen_names_[SCREEN_CREATE_SUPERVISED_USER_FLOW] =
    454       kScreenSupervisedUserCreationFlow;
    455   screen_names_[SCREEN_TERMS_OF_SERVICE] = kScreenTermsOfService;
    456   screen_names_[SCREEN_WRONG_HWID] = kScreenWrongHWID;
    457   screen_names_[SCREEN_AUTO_ENROLLMENT_CHECK] = kScreenAutoEnrollmentCheck;
    458   screen_names_[SCREEN_APP_LAUNCH_SPLASH] = kScreenAppLaunchSplash;
    459   screen_names_[SCREEN_CONFIRM_PASSWORD] = kScreenConfirmPassword;
    460   screen_names_[SCREEN_FATAL_ERROR] = kScreenFatalError;
    461   screen_names_[SCREEN_OOBE_CONTROLLER_PAIRING] = kScreenControllerPairing;
    462   screen_names_[SCREEN_OOBE_HOST_PAIRING] = kScreenHostPairing;
    463 
    464   screen_ids_.clear();
    465   for (size_t i = 0; i < screen_names_.size(); ++i)
    466     screen_ids_[screen_names_[i]] = static_cast<Screen>(i);
    467 }
    468 
    469 void OobeUI::AddScreenHandler(BaseScreenHandler* handler) {
    470   web_ui()->AddMessageHandler(handler);
    471   handlers_.push_back(handler);
    472 }
    473 
    474 void OobeUI::InitializeHandlers() {
    475   ready_ = true;
    476   for (size_t i = 0; i < ready_callbacks_.size(); ++i)
    477     ready_callbacks_[i].Run();
    478   ready_callbacks_.clear();
    479 
    480   // Notify 'initialize' for synchronously loaded screens.
    481   for (size_t i = 0; i < handlers_.size(); ++i) {
    482     if (handlers_[i]->async_assets_load_id().empty())
    483       handlers_[i]->InitializeBase();
    484   }
    485 }
    486 
    487 void OobeUI::OnScreenAssetsLoaded(const std::string& async_assets_load_id) {
    488   DCHECK(!async_assets_load_id.empty());
    489 
    490   for (size_t i = 0; i < handlers_.size(); ++i) {
    491     if (handlers_[i]->async_assets_load_id() == async_assets_load_id)
    492       handlers_[i]->InitializeBase();
    493   }
    494 }
    495 
    496 bool OobeUI::IsJSReady(const base::Closure& display_is_ready_callback) {
    497   if (!ready_)
    498     ready_callbacks_.push_back(display_is_ready_callback);
    499   return ready_;
    500 }
    501 
    502 void OobeUI::ShowOobeUI(bool show) {
    503   core_handler_->ShowOobeUI(show);
    504 }
    505 
    506 void OobeUI::ShowRetailModeLoginSpinner() {
    507   signin_screen_handler_->ShowRetailModeLoginSpinner();
    508 }
    509 
    510 void OobeUI::ShowSigninScreen(const LoginScreenContext& context,
    511                               SigninScreenHandlerDelegate* delegate,
    512                               NativeWindowDelegate* native_window_delegate) {
    513   signin_screen_handler_->SetDelegate(delegate);
    514   signin_screen_handler_->SetNativeWindowDelegate(native_window_delegate);
    515 
    516   LoginScreenContext actual_context(context);
    517   actual_context.set_oobe_ui(core_handler_->show_oobe_ui());
    518   signin_screen_handler_->Show(actual_context);
    519 }
    520 
    521 void OobeUI::ResetSigninScreenHandlerDelegate() {
    522   signin_screen_handler_->SetDelegate(NULL);
    523   signin_screen_handler_->SetNativeWindowDelegate(NULL);
    524 }
    525 
    526 
    527 void OobeUI::AddObserver(Observer* observer) {
    528   observer_list_.AddObserver(observer);
    529 }
    530 
    531 void OobeUI::RemoveObserver(Observer* observer) {
    532   observer_list_.RemoveObserver(observer);
    533 }
    534 
    535 const std::string& OobeUI::GetScreenName(Screen screen) const {
    536   DCHECK(screen >= 0 && screen < SCREEN_UNKNOWN);
    537   return screen_names_[static_cast<size_t>(screen)];
    538 }
    539 
    540 void OobeUI::OnCurrentScreenChanged(const std::string& screen) {
    541   previous_screen_ = current_screen_;
    542   DCHECK(screen_ids_.count(screen))
    543       << "Screen should be registered in InitializeScreenMaps()";
    544   Screen new_screen = screen_ids_[screen];
    545   FOR_EACH_OBSERVER(Observer,
    546                     observer_list_,
    547                     OnCurrentScreenChanged(current_screen_, new_screen));
    548   current_screen_ = new_screen;
    549 }
    550 
    551 }  // namespace chromeos
    552