1 // Copyright 2013 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.
5 #include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handler.h"
7 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
8 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
9 #include "grit/browser_resources.h"
10 #include "grit/chrome_unscaled_resources.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/base/webui/web_ui_util.h"
19 const char kJsScreenPath[] = "login.AppLaunchSplashScreen";
25 AppLaunchSplashScreenHandler::AppLaunchSplashScreenHandler()
26 : BaseScreenHandler(kJsScreenPath),
29 state_(APP_LAUNCH_STATE_LOADING_AUTH_FILE) {
32 AppLaunchSplashScreenHandler::~AppLaunchSplashScreenHandler() {
35 void AppLaunchSplashScreenHandler::DeclareLocalizedValues(
36 LocalizedValuesBuilder* builder) {
38 builder->Add("appStartMessage", IDS_APP_START_NETWORK_WAIT_MESSAGE);
39 builder->Add("configureNetwork", IDS_APP_START_CONFIGURE_NETWORK);
41 const string16 product_os_name =
42 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME);
45 l10n_util::GetStringFUTF16(IDS_APP_START_BAILOUT_SHORTCUT_FORMAT,
50 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME));
53 void AppLaunchSplashScreenHandler::Initialize() {
55 show_on_init_ = false;
60 void AppLaunchSplashScreenHandler::Show(const std::string& app_id) {
62 if (!page_is_ready()) {
67 base::DictionaryValue data;
68 data.SetBoolean("shortcutEnabled",
69 !KioskAppManager::Get()->GetDisableBailoutShortcut());
71 // |data| will take ownership of |app_info|.
72 base::DictionaryValue *app_info = new base::DictionaryValue();
73 PopulateAppInfo(app_info);
74 data.Set("appInfo", app_info);
76 SetLaunchText(l10n_util::GetStringUTF8(GetProgressMessageFromState(state_)));
77 ShowScreen(OobeUI::kScreenAppLaunchSplash, &data);
80 void AppLaunchSplashScreenHandler::RegisterMessages() {
81 AddCallback("configureNetwork",
82 &AppLaunchSplashScreenHandler::HandleConfigureNetwork);
83 AddCallback("cancelAppLaunch",
84 &AppLaunchSplashScreenHandler::HandleCancelAppLaunch);
87 void AppLaunchSplashScreenHandler::PrepareToShow() {
90 void AppLaunchSplashScreenHandler::Hide() {
93 void AppLaunchSplashScreenHandler::ToggleNetworkConfig(bool visible) {
94 CallJS("toggleNetworkConfig", visible);
97 void AppLaunchSplashScreenHandler::UpdateAppLaunchState(AppLaunchState state) {
102 if (page_is_ready()) {
104 l10n_util::GetStringUTF8(GetProgressMessageFromState(state_)));
108 void AppLaunchSplashScreenHandler::SetDelegate(
109 AppLaunchSplashScreenHandler::Delegate* delegate) {
110 delegate_ = delegate;
113 void AppLaunchSplashScreenHandler::PopulateAppInfo(
114 base::DictionaryValue* out_info) {
115 KioskAppManager::App app;
116 KioskAppManager::Get()->GetApp(app_id_, &app);
118 if (app.name.empty())
119 app.name = l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME);
121 if (app.icon.isNull()) {
122 app.icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
123 IDR_PRODUCT_LOGO_128);
126 out_info->SetString("name", app.name);
127 out_info->SetString("iconURL", webui::GetBitmapDataUrl(*app.icon.bitmap()));
130 void AppLaunchSplashScreenHandler::SetLaunchText(const std::string& text) {
131 CallJS("updateMessage", text);
134 int AppLaunchSplashScreenHandler::GetProgressMessageFromState(
135 AppLaunchState state) {
137 case APP_LAUNCH_STATE_LOADING_AUTH_FILE:
138 case APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE:
139 // TODO(zelidrag): Add better string for this one than "Please wait..."
140 return IDS_SYNC_SETUP_SPINNER_TITLE;
141 case APP_LAUNCH_STATE_PREPARING_NETWORK:
142 return IDS_APP_START_NETWORK_WAIT_MESSAGE;
143 case APP_LAUNCH_STATE_INSTALLING_APPLICATION:
144 return IDS_APP_START_APP_WAIT_MESSAGE;
145 case APP_LAUNCH_STATE_WAITING_APP_WINDOW:
146 return IDS_APP_START_WAIT_FOR_APP_WINDOW_MESSAGE;
147 case APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT:
148 return IDS_APP_START_NETWORK_WAIT_TIMEOUT_MESSAGE;
150 return IDS_APP_START_NETWORK_WAIT_MESSAGE;
153 void AppLaunchSplashScreenHandler::HandleConfigureNetwork() {
155 delegate_->OnConfigureNetwork();
157 LOG(WARNING) << "No delegate set to handle network configuration.";
160 void AppLaunchSplashScreenHandler::HandleCancelAppLaunch() {
162 delegate_->OnCancelAppLaunch();
164 LOG(WARNING) << "No delegate set to handle cancel app launch";
167 } // namespace chromeos