| 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 <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/grit/chrome_unscaled_resources.h" |
| 12 #include "chrome/grit/chromium_strings.h" |
| 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/login/localized_values_builder.h" |
| 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/base/webui/web_ui_util.h" |
| 18 #include "ui/gfx/image/image_skia.h" |
| 19 |
| 20 namespace { |
| 21 |
| 22 constexpr char kJsScreenPath[] = "login.ArcKioskSplashScreen"; |
| 23 } |
| 24 |
| 25 namespace chromeos { |
| 26 |
| 27 ArcKioskSplashScreenHandler::ArcKioskSplashScreenHandler() |
| 28 : BaseScreenHandler(kJsScreenPath) {} |
| 29 |
| 30 ArcKioskSplashScreenHandler::~ArcKioskSplashScreenHandler() = default; |
| 31 |
| 32 void ArcKioskSplashScreenHandler::DeclareLocalizedValues( |
| 33 ::login::LocalizedValuesBuilder* builder) { |
| 34 builder->Add("arcKioskStartMessage", IDS_APP_START_APP_WAIT_MESSAGE); |
| 35 |
| 36 const base::string16 product_os_name = |
| 37 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME); |
| 38 builder->Add("arcKioskShortcutInfo", |
| 39 l10n_util::GetStringFUTF16(IDS_APP_START_BAILOUT_SHORTCUT_FORMAT, |
| 40 product_os_name)); |
| 41 builder->Add("arcKioskProductName", product_os_name); |
| 42 } |
| 43 |
| 44 void ArcKioskSplashScreenHandler::Initialize() { |
| 45 if (!show_on_init_) |
| 46 return; |
| 47 show_on_init_ = false; |
| 48 Show(); |
| 49 } |
| 50 |
| 51 void ArcKioskSplashScreenHandler::Show() { |
| 52 if (!page_is_ready()) { |
| 53 show_on_init_ = true; |
| 54 return; |
| 55 } |
| 56 |
| 57 base::DictionaryValue data; |
| 58 // |data| will take ownership of |app_info|. |
| 59 std::unique_ptr<base::DictionaryValue> app_info = |
| 60 base::MakeUnique<base::DictionaryValue>(); |
| 61 PopulateAppInfo(app_info.get()); |
| 62 data.Set("appInfo", std::move(app_info)); |
| 63 ShowScreenWithData(OobeScreen::SCREEN_ARC_KIOSK_SPLASH, &data); |
| 64 } |
| 65 |
| 66 void ArcKioskSplashScreenHandler::RegisterMessages() { |
| 67 AddCallback("cancelArcKioskLaunch", |
| 68 &ArcKioskSplashScreenHandler::HandleCancelArcKioskLaunch); |
| 69 } |
| 70 |
| 71 void ArcKioskSplashScreenHandler::UpdateArcKioskState(ArcKioskState state) { |
| 72 if (!page_is_ready()) |
| 73 return; |
| 74 SetLaunchText(l10n_util::GetStringUTF8(GetProgressMessageFromState(state))); |
| 75 } |
| 76 |
| 77 void ArcKioskSplashScreenHandler::SetDelegate( |
| 78 ArcKioskSplashScreenHandler::Delegate* delegate) { |
| 79 delegate_ = delegate; |
| 80 } |
| 81 |
| 82 void ArcKioskSplashScreenHandler::PopulateAppInfo( |
| 83 base::DictionaryValue* out_info) { |
| 84 out_info->SetString("name", l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME)); |
| 85 out_info->SetString( |
| 86 "iconURL", |
| 87 webui::GetBitmapDataUrl(*ResourceBundle::GetSharedInstance() |
| 88 .GetImageSkiaNamed(IDR_PRODUCT_LOGO_128) |
| 89 ->bitmap())); |
| 90 } |
| 91 |
| 92 void ArcKioskSplashScreenHandler::SetLaunchText(const std::string& text) { |
| 93 CallJS("updateArcKioskMessage", text); |
| 94 } |
| 95 |
| 96 int ArcKioskSplashScreenHandler::GetProgressMessageFromState( |
| 97 ArcKioskState state) { |
| 98 switch (state) { |
| 99 case ArcKioskState::STARTING_SESSION: |
| 100 return IDS_SYNC_SETUP_SPINNER_TITLE; |
| 101 case ArcKioskState::WAITING_APP_LAUNCH: |
| 102 return IDS_APP_START_APP_WAIT_MESSAGE; |
| 103 case ArcKioskState::WAITING_APP_WINDOW: |
| 104 return IDS_APP_START_WAIT_FOR_APP_WINDOW_MESSAGE; |
| 105 default: |
| 106 NOTREACHED(); |
| 107 break; |
| 108 } |
| 109 return IDS_SYNC_SETUP_SPINNER_TITLE; |
| 110 } |
| 111 |
| 112 void ArcKioskSplashScreenHandler::HandleCancelArcKioskLaunch() { |
| 113 if (!delegate_) { |
| 114 LOG(WARNING) << "No delegate set to handle cancel app launch"; |
| 115 return; |
| 116 } |
| 117 delegate_->OnCancelArcKioskLaunch(); |
| 118 } |
| 119 |
| 120 } // namespace chromeos |
| OLD | NEW |