1 // Copyright (c) 2012 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/update_screen_handler.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
10 #include "grit/chromium_strings.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
16 const char kJsScreenPath
[] = "login.UpdateScreen";
22 UpdateScreenHandler::UpdateScreenHandler()
23 : BaseScreenHandler(kJsScreenPath
),
25 show_on_init_(false) {
28 UpdateScreenHandler::~UpdateScreenHandler() {
30 screen_
->OnActorDestroyed(this);
33 void UpdateScreenHandler::DeclareLocalizedValues(
34 LocalizedValuesBuilder
* builder
) {
35 builder
->AddF("checkingForUpdatesMsg",
36 IDS_CHECKING_FOR_UPDATE_MSG
, IDS_SHORT_PRODUCT_NAME
);
37 builder
->AddF("installingUpdateDesc",
38 IDS_UPDATE_MSG
, IDS_SHORT_PRODUCT_NAME
);
40 builder
->Add("updateScreenTitle", IDS_UPDATE_SCREEN_TITLE
);
41 builder
->Add("checkingForUpdates", IDS_CHECKING_FOR_UPDATES
);
42 builder
->Add("downloading", IDS_DOWNLOADING
);
43 builder
->Add("downloadingTimeLeftLong", IDS_DOWNLOADING_TIME_LEFT_LONG
);
44 builder
->Add("downloadingTimeLeftStatusOneHour",
45 IDS_DOWNLOADING_TIME_LEFT_STATUS_ONE_HOUR
);
46 builder
->Add("downloadingTimeLeftStatusMinutes",
47 IDS_DOWNLOADING_TIME_LEFT_STATUS_MINUTES
);
48 builder
->Add("downloadingTimeLeftSmall", IDS_DOWNLOADING_TIME_LEFT_SMALL
);
50 #if !defined(OFFICIAL_BUILD)
51 builder
->Add("cancelUpdateHint", IDS_UPDATE_CANCEL
);
52 builder
->Add("cancelledUpdateMessage", IDS_UPDATE_CANCELLED
);
54 builder
->Add("cancelUpdateHint", IDS_EMPTY_STRING
);
55 builder
->Add("cancelledUpdateMessage", IDS_EMPTY_STRING
);
59 void UpdateScreenHandler::Initialize() {
62 show_on_init_
= false;
66 void UpdateScreenHandler::SetDelegate(UpdateScreenActor::Delegate
* screen
) {
70 void UpdateScreenHandler::Show() {
71 if (!page_is_ready()) {
75 ShowScreen(OobeUI::kScreenOobeUpdate
, NULL
);
76 #if !defined(OFFICIAL_BUILD)
77 CallJS("enableUpdateCancel");
81 void UpdateScreenHandler::Hide() {
84 void UpdateScreenHandler::PrepareToShow() {
87 void UpdateScreenHandler::ShowManualRebootInfo() {
88 CallJS("setUpdateMessage", l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED
));
91 void UpdateScreenHandler::SetProgress(int progress
) {
92 CallJS("setUpdateProgress", progress
);
95 void UpdateScreenHandler::ShowEstimatedTimeLeft(bool visible
) {
96 CallJS("showEstimatedTimeLeft", visible
);
99 void UpdateScreenHandler::SetEstimatedTimeLeft(const base::TimeDelta
& time
) {
100 CallJS("setEstimatedTimeLeft", time
.InSecondsF());
103 void UpdateScreenHandler::ShowProgressMessage(bool visible
) {
104 CallJS("showProgressMessage", visible
);
107 void UpdateScreenHandler::SetProgressMessage(ProgressMessage message
) {
108 scoped_ptr
<base::StringValue
> progress_message
;
110 case PROGRESS_MESSAGE_UPDATE_AVAILABLE
:
111 progress_message
.reset(base::Value::CreateStringValue(
112 l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE
)));
114 case PROGRESS_MESSAGE_INSTALLING_UPDATE
:
115 progress_message
.reset(base::Value::CreateStringValue(
116 l10n_util::GetStringFUTF16(IDS_INSTALLING_UPDATE
,
117 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME
))));
119 case PROGRESS_MESSAGE_VERIFYING
:
120 progress_message
.reset(base::Value::CreateStringValue(
121 l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING
)));
123 case PROGRESS_MESSAGE_FINALIZING
:
124 progress_message
.reset(base::Value::CreateStringValue(
125 l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING
)));
130 if (progress_message
.get())
131 CallJS("setProgressMessage", *progress_message
);
134 void UpdateScreenHandler::ShowCurtain(bool visible
) {
135 CallJS("showUpdateCurtain", visible
);
138 void UpdateScreenHandler::RegisterMessages() {
139 #if !defined(OFFICIAL_BUILD)
140 AddCallback("cancelUpdate", &UpdateScreenHandler::HandleUpdateCancel
);
144 void UpdateScreenHandler::OnConnectToNetworkRequested(
145 const std::string
& service_path
) {
147 screen_
->OnConnectToNetworkRequested(service_path
);
150 #if !defined(OFFICIAL_BUILD)
151 void UpdateScreenHandler::HandleUpdateCancel() {
152 screen_
->CancelUpdate();
156 } // namespace chromeos