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/chromeos/login/screens/network_error.h"
9 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
10 #include "chrome/grit/chromium_strings.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "chromeos/network/network_state.h"
13 #include "chromeos/network/network_state_handler.h"
14 #include "components/login/localized_values_builder.h"
15 #include "grit/chrome_unscaled_resources.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/base/webui/web_ui_util.h"
22 const char kJsScreenPath
[] = "login.AppLaunchSplashScreen";
24 // Returns network name by service path.
25 std::string
GetNetworkName(const std::string
& service_path
) {
26 const chromeos::NetworkState
* network
=
27 chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState(
31 return network
->name();
38 AppLaunchSplashScreenHandler::AppLaunchSplashScreenHandler(
39 const scoped_refptr
<NetworkStateInformer
>& network_state_informer
,
40 NetworkErrorModel
* network_error_model
)
41 : BaseScreenHandler(kJsScreenPath
),
44 state_(APP_LAUNCH_STATE_LOADING_AUTH_FILE
),
45 network_state_informer_(network_state_informer
),
46 network_error_model_(network_error_model
),
48 network_config_done_(false),
49 network_config_requested_(false) {
50 network_state_informer_
->AddObserver(this);
53 AppLaunchSplashScreenHandler::~AppLaunchSplashScreenHandler() {
54 network_state_informer_
->RemoveObserver(this);
57 void AppLaunchSplashScreenHandler::DeclareLocalizedValues(
58 ::login::LocalizedValuesBuilder
* builder
) {
59 builder
->Add("appStartMessage", IDS_APP_START_NETWORK_WAIT_MESSAGE
);
60 builder
->Add("configureNetwork", IDS_APP_START_CONFIGURE_NETWORK
);
62 const base::string16 product_os_name
=
63 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME
);
66 l10n_util::GetStringFUTF16(IDS_APP_START_BAILOUT_SHORTCUT_FORMAT
,
71 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME
));
74 void AppLaunchSplashScreenHandler::Initialize() {
76 show_on_init_
= false;
81 void AppLaunchSplashScreenHandler::Show(const std::string
& app_id
) {
83 if (!page_is_ready()) {
88 base::DictionaryValue data
;
89 data
.SetBoolean("shortcutEnabled",
90 !KioskAppManager::Get()->GetDisableBailoutShortcut());
92 // |data| will take ownership of |app_info|.
93 base::DictionaryValue
*app_info
= new base::DictionaryValue();
94 PopulateAppInfo(app_info
);
95 data
.Set("appInfo", app_info
);
97 SetLaunchText(l10n_util::GetStringUTF8(GetProgressMessageFromState(state_
)));
98 ShowScreen(OobeUI::kScreenAppLaunchSplash
, &data
);
101 void AppLaunchSplashScreenHandler::RegisterMessages() {
102 AddCallback("configureNetwork",
103 &AppLaunchSplashScreenHandler::HandleConfigureNetwork
);
104 AddCallback("cancelAppLaunch",
105 &AppLaunchSplashScreenHandler::HandleCancelAppLaunch
);
106 AddCallback("continueAppLaunch",
107 &AppLaunchSplashScreenHandler::HandleContinueAppLaunch
);
108 AddCallback("networkConfigRequest",
109 &AppLaunchSplashScreenHandler::HandleNetworkConfigRequested
);
112 void AppLaunchSplashScreenHandler::PrepareToShow() {
115 void AppLaunchSplashScreenHandler::Hide() {
118 void AppLaunchSplashScreenHandler::ToggleNetworkConfig(bool visible
) {
119 CallJS("toggleNetworkConfig", visible
);
122 void AppLaunchSplashScreenHandler::UpdateAppLaunchState(AppLaunchState state
) {
127 if (page_is_ready()) {
129 l10n_util::GetStringUTF8(GetProgressMessageFromState(state_
)));
131 UpdateState(NetworkError::ERROR_REASON_UPDATE
);
134 void AppLaunchSplashScreenHandler::SetDelegate(
135 AppLaunchSplashScreenHandler::Delegate
* delegate
) {
136 delegate_
= delegate
;
139 void AppLaunchSplashScreenHandler::ShowNetworkConfigureUI() {
140 NetworkStateInformer::State state
= network_state_informer_
->state();
141 if (state
== NetworkStateInformer::ONLINE
) {
142 online_state_
= true;
143 if (!network_config_requested_
) {
144 delegate_
->OnNetworkStateChanged(true);
149 const std::string network_path
= network_state_informer_
->network_path();
150 const std::string network_name
= GetNetworkName(network_path
);
152 network_error_model_
->SetUIState(NetworkError::UI_STATE_KIOSK_MODE
);
153 network_error_model_
->AllowGuestSignin(false);
154 network_error_model_
->AllowOfflineLogin(false);
157 case NetworkStateInformer::CAPTIVE_PORTAL
: {
158 network_error_model_
->SetErrorState(NetworkError::ERROR_STATE_PORTAL
,
160 network_error_model_
->FixCaptivePortal();
164 case NetworkStateInformer::PROXY_AUTH_REQUIRED
: {
165 network_error_model_
->SetErrorState(NetworkError::ERROR_STATE_PROXY
,
169 case NetworkStateInformer::OFFLINE
: {
170 network_error_model_
->SetErrorState(NetworkError::ERROR_STATE_OFFLINE
,
174 case NetworkStateInformer::ONLINE
: {
175 network_error_model_
->SetErrorState(
176 NetworkError::ERROR_STATE_KIOSK_ONLINE
, network_name
);
180 network_error_model_
->SetErrorState(NetworkError::ERROR_STATE_OFFLINE
,
186 OobeUI::Screen screen
= OobeUI::SCREEN_UNKNOWN
;
187 OobeUI
* oobe_ui
= static_cast<OobeUI
*>(web_ui()->GetController());
189 screen
= oobe_ui
->current_screen();
191 if (screen
!= OobeUI::SCREEN_ERROR_MESSAGE
)
192 network_error_model_
->SetParentScreen(OobeUI::SCREEN_APP_LAUNCH_SPLASH
);
193 network_error_model_
->Show();
196 bool AppLaunchSplashScreenHandler::IsNetworkReady() {
197 return network_state_informer_
->state() == NetworkStateInformer::ONLINE
;
200 void AppLaunchSplashScreenHandler::OnNetworkReady() {
201 // Purposely leave blank because the online case is handled in UpdateState
205 void AppLaunchSplashScreenHandler::UpdateState(
206 NetworkError::ErrorReason reason
) {
208 (state_
!= APP_LAUNCH_STATE_PREPARING_NETWORK
&&
209 state_
!= APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT
)) {
213 bool new_online_state
=
214 network_state_informer_
->state() == NetworkStateInformer::ONLINE
;
215 delegate_
->OnNetworkStateChanged(new_online_state
);
217 online_state_
= new_online_state
;
220 void AppLaunchSplashScreenHandler::PopulateAppInfo(
221 base::DictionaryValue
* out_info
) {
222 KioskAppManager::App app
;
223 KioskAppManager::Get()->GetApp(app_id_
, &app
);
225 if (app
.name
.empty())
226 app
.name
= l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME
);
228 if (app
.icon
.isNull()) {
229 app
.icon
= *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
230 IDR_PRODUCT_LOGO_128
);
233 out_info
->SetString("name", app
.name
);
234 out_info
->SetString("iconURL", webui::GetBitmapDataUrl(*app
.icon
.bitmap()));
237 void AppLaunchSplashScreenHandler::SetLaunchText(const std::string
& text
) {
238 CallJS("updateMessage", text
);
241 int AppLaunchSplashScreenHandler::GetProgressMessageFromState(
242 AppLaunchState state
) {
244 case APP_LAUNCH_STATE_LOADING_AUTH_FILE
:
245 case APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE
:
246 // TODO(zelidrag): Add better string for this one than "Please wait..."
247 return IDS_SYNC_SETUP_SPINNER_TITLE
;
248 case APP_LAUNCH_STATE_PREPARING_NETWORK
:
249 return IDS_APP_START_NETWORK_WAIT_MESSAGE
;
250 case APP_LAUNCH_STATE_INSTALLING_APPLICATION
:
251 return IDS_APP_START_APP_WAIT_MESSAGE
;
252 case APP_LAUNCH_STATE_WAITING_APP_WINDOW
:
253 return IDS_APP_START_WAIT_FOR_APP_WINDOW_MESSAGE
;
254 case APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT
:
255 return IDS_APP_START_NETWORK_WAIT_TIMEOUT_MESSAGE
;
257 return IDS_APP_START_NETWORK_WAIT_MESSAGE
;
260 void AppLaunchSplashScreenHandler::HandleConfigureNetwork() {
262 delegate_
->OnConfigureNetwork();
264 LOG(WARNING
) << "No delegate set to handle network configuration.";
267 void AppLaunchSplashScreenHandler::HandleCancelAppLaunch() {
269 delegate_
->OnCancelAppLaunch();
271 LOG(WARNING
) << "No delegate set to handle cancel app launch";
274 void AppLaunchSplashScreenHandler::HandleNetworkConfigRequested() {
275 if (!delegate_
|| network_config_done_
)
278 network_config_requested_
= true;
279 delegate_
->OnNetworkConfigRequested(true);
282 void AppLaunchSplashScreenHandler::HandleContinueAppLaunch() {
283 DCHECK(online_state_
);
284 if (delegate_
&& online_state_
) {
285 network_config_requested_
= false;
286 network_config_done_
= true;
287 delegate_
->OnNetworkConfigRequested(false);
292 } // namespace chromeos