Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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/arc_kiosk_splash_screen_handler .h" | |
| 6 | |
| 7 #include "chrome/grit/chrome_unscaled_resources.h" | |
| 8 #include "chrome/grit/chromium_strings.h" | |
| 9 #include "chrome/grit/generated_resources.h" | |
| 10 #include "components/login/localized_values_builder.h" | |
| 11 #include "ui/base/l10n/l10n_util.h" | |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/base/webui/web_ui_util.h" | |
| 14 #include "ui/gfx/image/image_skia.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 const char kJsScreenPath[] = "login.ArcKioskSplashScreen"; | |
| 
 
Luis Héctor Chávez
2017/01/24 18:40:24
nit: constexpr
 
Sergey Poromov
2017/01/25 14:29:22
Done.
 
 | |
| 19 | |
| 20 } // namespace | |
| 21 | |
| 22 namespace chromeos { | |
| 23 | |
| 24 ArcKioskSplashScreenHandler::ArcKioskSplashScreenHandler() | |
| 25 : BaseScreenHandler(kJsScreenPath), show_on_init_(false) {} | |
| 26 | |
| 27 ArcKioskSplashScreenHandler::~ArcKioskSplashScreenHandler() {} | |
| 
 
Luis Héctor Chávez
2017/01/24 18:40:24
nit: = default
 
Sergey Poromov
2017/01/25 14:29:22
Done.
 
 | |
| 28 | |
| 29 void ArcKioskSplashScreenHandler::DeclareLocalizedValues( | |
| 30 ::login::LocalizedValuesBuilder* builder) { | |
| 31 builder->Add("arcKioskStartMessage", IDS_APP_START_APP_WAIT_MESSAGE); | |
| 32 } | |
| 33 | |
| 34 void ArcKioskSplashScreenHandler::Initialize() { | |
| 35 if (show_on_init_) { | |
| 
 
Luis Héctor Chávez
2017/01/24 18:40:25
nit:
if (!show_on_init_)
  return;
 
Sergey Poromov
2017/01/25 14:29:22
Done.
 
 | |
| 36 show_on_init_ = false; | |
| 37 Show(); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 void ArcKioskSplashScreenHandler::Show() { | |
| 42 if (!page_is_ready()) { | |
| 43 show_on_init_ = true; | |
| 44 return; | |
| 45 } | |
| 46 | |
| 47 base::DictionaryValue data; | |
| 48 // |data| will take ownership of |app_info|. | |
| 49 base::DictionaryValue* app_info = new base::DictionaryValue(); | |
| 
 
Luis Héctor Chávez
2017/01/24 18:40:25
prefer to use 
std::unique_ptr<base::DictionaryVa
 
 | |
| 50 PopulateAppInfo(app_info); | |
| 51 data.Set("appInfo", app_info); | |
| 52 ShowScreenWithData(OobeScreen::SCREEN_ARC_KIOSK_SPLASH, &data); | |
| 53 } | |
| 54 | |
| 55 void ArcKioskSplashScreenHandler::RegisterMessages() { | |
| 56 AddCallback("cancelArcKioskLaunch", | |
| 57 &ArcKioskSplashScreenHandler::HandleCancelArcKioskLaunch); | |
| 58 } | |
| 59 | |
| 60 void ArcKioskSplashScreenHandler::UpdateArcKioskState(ArcKioskState state) { | |
| 61 if (page_is_ready()) { | |
| 
 
Luis Héctor Chávez
2017/01/24 18:40:25
nit:
if (!page_is_ready())
  return;
 
Sergey Poromov
2017/01/25 14:29:22
Done.
 
 | |
| 62 SetLaunchText(l10n_util::GetStringUTF8(GetProgressMessageFromState(state))); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 void ArcKioskSplashScreenHandler::SetDelegate( | |
| 67 ArcKioskSplashScreenHandler::Delegate* delegate) { | |
| 68 delegate_ = delegate; | |
| 69 } | |
| 70 | |
| 71 void ArcKioskSplashScreenHandler::PopulateAppInfo( | |
| 72 base::DictionaryValue* out_info) { | |
| 73 out_info->SetString("name", l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME)); | |
| 74 out_info->SetString( | |
| 75 "iconURL", | |
| 76 webui::GetBitmapDataUrl(*ResourceBundle::GetSharedInstance() | |
| 77 .GetImageSkiaNamed(IDR_PRODUCT_LOGO_128) | |
| 78 ->bitmap())); | |
| 79 } | |
| 80 | |
| 81 void ArcKioskSplashScreenHandler::SetLaunchText(const std::string& text) { | |
| 82 CallJS("updateArcKioskMessage", text); | |
| 83 } | |
| 84 | |
| 85 int ArcKioskSplashScreenHandler::GetProgressMessageFromState( | |
| 86 ArcKioskState state) { | |
| 87 switch (state) { | |
| 88 case ARC_KIOSK_STATE_STARTING_SESSION: | |
| 89 return IDS_SYNC_SETUP_SPINNER_TITLE; | |
| 90 case ARC_KIOSK_STATE_WAITING_APP_LAUNCH: | |
| 91 return IDS_APP_START_APP_WAIT_MESSAGE; | |
| 92 case ARC_KIOSK_STATE_WAITING_APP_WINDOW: | |
| 93 return IDS_APP_START_WAIT_FOR_APP_WINDOW_MESSAGE; | |
| 94 } | |
| 95 return IDS_SYNC_SETUP_SPINNER_TITLE; | |
| 96 } | |
| 97 | |
| 98 void ArcKioskSplashScreenHandler::HandleCancelArcKioskLaunch() { | |
| 99 if (delegate_) | |
| 
 
Luis Héctor Chávez
2017/01/24 18:40:25
nit:
if (!delegate_) {
  LOG(WARNING) << "No dele
 
Sergey Poromov
2017/01/25 14:29:22
Done.
 
 | |
| 100 delegate_->OnCancelArcKioskLaunch(); | |
| 101 else | |
| 102 LOG(WARNING) << "No delegate set to handle cancel app launch"; | |
| 103 } | |
| 104 | |
| 105 } // namespace chromeos | |
| OLD | NEW |