Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / chromeos / login / update_screen_handler.cc
blob96e93ba8d71190823bcff9a14e7dbd776f095300
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"
14 namespace {
16 const char kJsScreenPath[] = "login.UpdateScreen";
18 } // namespace
20 namespace chromeos {
22 UpdateScreenHandler::UpdateScreenHandler()
23 : BaseScreenHandler(kJsScreenPath),
24 screen_(NULL),
25 show_on_init_(false) {
28 UpdateScreenHandler::~UpdateScreenHandler() {
29 if (screen_)
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);
53 #else
54 builder->Add("cancelUpdateHint", IDS_EMPTY_STRING);
55 builder->Add("cancelledUpdateMessage", IDS_EMPTY_STRING);
56 #endif
59 void UpdateScreenHandler::Initialize() {
60 if (show_on_init_) {
61 Show();
62 show_on_init_ = false;
66 void UpdateScreenHandler::SetDelegate(UpdateScreenActor::Delegate* screen) {
67 screen_ = screen;
70 void UpdateScreenHandler::Show() {
71 if (!page_is_ready()) {
72 show_on_init_ = true;
73 return;
75 ShowScreen(OobeUI::kScreenOobeUpdate, NULL);
76 #if !defined(OFFICIAL_BUILD)
77 CallJS("enableUpdateCancel");
78 #endif
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;
109 switch (message) {
110 case PROGRESS_MESSAGE_UPDATE_AVAILABLE:
111 progress_message.reset(base::Value::CreateStringValue(
112 l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE)));
113 break;
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))));
118 break;
119 case PROGRESS_MESSAGE_VERIFYING:
120 progress_message.reset(base::Value::CreateStringValue(
121 l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING)));
122 break;
123 case PROGRESS_MESSAGE_FINALIZING:
124 progress_message.reset(base::Value::CreateStringValue(
125 l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING)));
126 break;
127 default:
128 NOTREACHED();
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);
141 #endif
144 void UpdateScreenHandler::OnConnectToNetworkRequested(
145 const std::string& service_path) {
146 if (screen_)
147 screen_->OnConnectToNetworkRequested(service_path);
150 #if !defined(OFFICIAL_BUILD)
151 void UpdateScreenHandler::HandleUpdateCancel() {
152 screen_->CancelUpdate();
154 #endif
156 } // namespace chromeos