1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handler.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
#include "chrome/browser/chromeos/login/screens/network_error.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_screen.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "components/login/localized_values_builder.h"
#include "grit/chrome_unscaled_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/webui/web_ui_util.h"
namespace {
const char kJsScreenPath[] = "login.AppLaunchSplashScreen";
// Returns network name by service path.
std::string GetNetworkName(const std::string& service_path) {
const chromeos::NetworkState* network =
chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState(
service_path);
if (!network)
return std::string();
return network->name();
}
} // namespace
namespace chromeos {
AppLaunchSplashScreenHandler::AppLaunchSplashScreenHandler(
const scoped_refptr<NetworkStateInformer>& network_state_informer,
NetworkErrorModel* network_error_model)
: BaseScreenHandler(kJsScreenPath),
delegate_(NULL),
show_on_init_(false),
state_(APP_LAUNCH_STATE_LOADING_AUTH_FILE),
network_state_informer_(network_state_informer),
network_error_model_(network_error_model),
online_state_(false),
network_config_done_(false),
network_config_requested_(false) {
network_state_informer_->AddObserver(this);
}
AppLaunchSplashScreenHandler::~AppLaunchSplashScreenHandler() {
network_state_informer_->RemoveObserver(this);
}
void AppLaunchSplashScreenHandler::DeclareLocalizedValues(
::login::LocalizedValuesBuilder* builder) {
builder->Add("appStartMessage", IDS_APP_START_NETWORK_WAIT_MESSAGE);
builder->Add("configureNetwork", IDS_APP_START_CONFIGURE_NETWORK);
const base::string16 product_os_name =
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME);
builder->Add(
"shortcutInfo",
l10n_util::GetStringFUTF16(IDS_APP_START_BAILOUT_SHORTCUT_FORMAT,
product_os_name));
builder->Add(
"productName",
l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME));
}
void AppLaunchSplashScreenHandler::Initialize() {
if (show_on_init_) {
show_on_init_ = false;
Show(app_id_);
}
}
void AppLaunchSplashScreenHandler::Show(const std::string& app_id) {
app_id_ = app_id;
if (!page_is_ready()) {
show_on_init_ = true;
return;
}
base::DictionaryValue data;
data.SetBoolean("shortcutEnabled",
!KioskAppManager::Get()->GetDisableBailoutShortcut());
// |data| will take ownership of |app_info|.
base::DictionaryValue *app_info = new base::DictionaryValue();
PopulateAppInfo(app_info);
data.Set("appInfo", app_info);
SetLaunchText(l10n_util::GetStringUTF8(GetProgressMessageFromState(state_)));
ShowScreenWithData(OobeScreen::SCREEN_APP_LAUNCH_SPLASH, &data);
}
void AppLaunchSplashScreenHandler::RegisterMessages() {
AddCallback("configureNetwork",
&AppLaunchSplashScreenHandler::HandleConfigureNetwork);
AddCallback("cancelAppLaunch",
&AppLaunchSplashScreenHandler::HandleCancelAppLaunch);
AddCallback("continueAppLaunch",
&AppLaunchSplashScreenHandler::HandleContinueAppLaunch);
AddCallback("networkConfigRequest",
&AppLaunchSplashScreenHandler::HandleNetworkConfigRequested);
}
void AppLaunchSplashScreenHandler::PrepareToShow() {
}
void AppLaunchSplashScreenHandler::Hide() {
}
void AppLaunchSplashScreenHandler::ToggleNetworkConfig(bool visible) {
CallJS("toggleNetworkConfig", visible);
}
void AppLaunchSplashScreenHandler::UpdateAppLaunchState(AppLaunchState state) {
if (state == state_)
return;
state_ = state;
if (page_is_ready()) {
SetLaunchText(
l10n_util::GetStringUTF8(GetProgressMessageFromState(state_)));
}
UpdateState(NetworkError::ERROR_REASON_UPDATE);
}
void AppLaunchSplashScreenHandler::SetDelegate(
AppLaunchSplashScreenHandler::Delegate* delegate) {
delegate_ = delegate;
}
void AppLaunchSplashScreenHandler::ShowNetworkConfigureUI() {
NetworkStateInformer::State state = network_state_informer_->state();
if (state == NetworkStateInformer::ONLINE) {
online_state_ = true;
if (!network_config_requested_) {
delegate_->OnNetworkStateChanged(true);
return;
}
}
const std::string network_path = network_state_informer_->network_path();
const std::string network_name = GetNetworkName(network_path);
network_error_model_->SetUIState(NetworkError::UI_STATE_KIOSK_MODE);
network_error_model_->AllowGuestSignin(false);
network_error_model_->AllowOfflineLogin(false);
switch (state) {
case NetworkStateInformer::CAPTIVE_PORTAL: {
network_error_model_->SetErrorState(NetworkError::ERROR_STATE_PORTAL,
network_name);
network_error_model_->FixCaptivePortal();
break;
}
case NetworkStateInformer::PROXY_AUTH_REQUIRED: {
network_error_model_->SetErrorState(NetworkError::ERROR_STATE_PROXY,
network_name);
break;
}
case NetworkStateInformer::OFFLINE: {
network_error_model_->SetErrorState(NetworkError::ERROR_STATE_OFFLINE,
network_name);
break;
}
case NetworkStateInformer::ONLINE: {
network_error_model_->SetErrorState(
NetworkError::ERROR_STATE_KIOSK_ONLINE, network_name);
break;
}
default:
network_error_model_->SetErrorState(NetworkError::ERROR_STATE_OFFLINE,
network_name);
NOTREACHED();
break;
}
OobeScreen screen = OobeScreen::SCREEN_UNKNOWN;
OobeUI* oobe_ui = static_cast<OobeUI*>(web_ui()->GetController());
if (oobe_ui)
screen = oobe_ui->current_screen();
if (screen != OobeScreen::SCREEN_ERROR_MESSAGE)
network_error_model_->SetParentScreen(OobeScreen::SCREEN_APP_LAUNCH_SPLASH);
network_error_model_->Show();
}
bool AppLaunchSplashScreenHandler::IsNetworkReady() {
return network_state_informer_->state() == NetworkStateInformer::ONLINE;
}
void AppLaunchSplashScreenHandler::OnNetworkReady() {
// Purposely leave blank because the online case is handled in UpdateState
// call below.
}
void AppLaunchSplashScreenHandler::UpdateState(
NetworkError::ErrorReason reason) {
if (!delegate_ ||
(state_ != APP_LAUNCH_STATE_PREPARING_NETWORK &&
state_ != APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT)) {
return;
}
bool new_online_state =
network_state_informer_->state() == NetworkStateInformer::ONLINE;
delegate_->OnNetworkStateChanged(new_online_state);
online_state_ = new_online_state;
}
void AppLaunchSplashScreenHandler::PopulateAppInfo(
base::DictionaryValue* out_info) {
KioskAppManager::App app;
KioskAppManager::Get()->GetApp(app_id_, &app);
if (app.name.empty())
app.name = l10n_util::GetStringUTF8(IDS_SHORT_PRODUCT_NAME);
if (app.icon.isNull()) {
app.icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_PRODUCT_LOGO_128);
}
out_info->SetString("name", app.name);
out_info->SetString("iconURL", webui::GetBitmapDataUrl(*app.icon.bitmap()));
}
void AppLaunchSplashScreenHandler::SetLaunchText(const std::string& text) {
CallJS("updateMessage", text);
}
int AppLaunchSplashScreenHandler::GetProgressMessageFromState(
AppLaunchState state) {
switch (state) {
case APP_LAUNCH_STATE_LOADING_AUTH_FILE:
case APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE:
// TODO(zelidrag): Add better string for this one than "Please wait..."
return IDS_SYNC_SETUP_SPINNER_TITLE;
case APP_LAUNCH_STATE_PREPARING_NETWORK:
return IDS_APP_START_NETWORK_WAIT_MESSAGE;
case APP_LAUNCH_STATE_INSTALLING_APPLICATION:
return IDS_APP_START_APP_WAIT_MESSAGE;
case APP_LAUNCH_STATE_WAITING_APP_WINDOW:
return IDS_APP_START_WAIT_FOR_APP_WINDOW_MESSAGE;
case APP_LAUNCH_STATE_NETWORK_WAIT_TIMEOUT:
return IDS_APP_START_NETWORK_WAIT_TIMEOUT_MESSAGE;
}
return IDS_APP_START_NETWORK_WAIT_MESSAGE;
}
void AppLaunchSplashScreenHandler::HandleConfigureNetwork() {
if (delegate_)
delegate_->OnConfigureNetwork();
else
LOG(WARNING) << "No delegate set to handle network configuration.";
}
void AppLaunchSplashScreenHandler::HandleCancelAppLaunch() {
if (delegate_)
delegate_->OnCancelAppLaunch();
else
LOG(WARNING) << "No delegate set to handle cancel app launch";
}
void AppLaunchSplashScreenHandler::HandleNetworkConfigRequested() {
if (!delegate_ || network_config_done_)
return;
network_config_requested_ = true;
delegate_->OnNetworkConfigRequested(true);
}
void AppLaunchSplashScreenHandler::HandleContinueAppLaunch() {
DCHECK(online_state_);
if (delegate_ && online_state_) {
network_config_requested_ = false;
network_config_done_ = true;
delegate_->OnNetworkConfigRequested(false);
Show(app_id_);
}
}
} // namespace chromeos
|