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. 4 5 #include "chrome/browser/ui/webui/chromeos/login/update_screen_handler.h" 6 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" 13 14 namespace { 15 16 const char kJsScreenPath[] = "login.UpdateScreen"; 17 18 } // namespace 19 20 namespace chromeos { 21 22 UpdateScreenHandler::UpdateScreenHandler() 23 : BaseScreenHandler(kJsScreenPath), 24 screen_(NULL), 25 show_on_init_(false) { 26 } 27 28 UpdateScreenHandler::~UpdateScreenHandler() { 29 if (screen_) 30 screen_->OnActorDestroyed(this); 31 } 32 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); 39 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); 49 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 57 } 58 59 void UpdateScreenHandler::Initialize() { 60 if (show_on_init_) { 61 Show(); 62 show_on_init_ = false; 63 } 64 } 65 66 void UpdateScreenHandler::SetDelegate(UpdateScreenActor::Delegate* screen) { 67 screen_ = screen; 68 } 69 70 void UpdateScreenHandler::Show() { 71 if (!page_is_ready()) { 72 show_on_init_ = true; 73 return; 74 } 75 ShowScreen(OobeUI::kScreenOobeUpdate, NULL); 76 #if !defined(OFFICIAL_BUILD) 77 CallJS("enableUpdateCancel"); 78 #endif 79 } 80 81 void UpdateScreenHandler::Hide() { 82 } 83 84 void UpdateScreenHandler::PrepareToShow() { 85 } 86 87 void UpdateScreenHandler::ShowManualRebootInfo() { 88 CallJS("setUpdateMessage", l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED)); 89 } 90 91 void UpdateScreenHandler::SetProgress(int progress) { 92 CallJS("setUpdateProgress", progress); 93 } 94 95 void UpdateScreenHandler::ShowEstimatedTimeLeft(bool visible) { 96 CallJS("showEstimatedTimeLeft", visible); 97 } 98 99 void UpdateScreenHandler::SetEstimatedTimeLeft(const base::TimeDelta& time) { 100 CallJS("setEstimatedTimeLeft", time.InSecondsF()); 101 } 102 103 void UpdateScreenHandler::ShowProgressMessage(bool visible) { 104 CallJS("showProgressMessage", visible); 105 } 106 107 void UpdateScreenHandler::SetProgressMessage(ProgressMessage message) { 108 scoped_ptr<StringValue> progress_message; 109 switch (message) { 110 case PROGRESS_MESSAGE_UPDATE_AVAILABLE: 111 progress_message.reset(Value::CreateStringValue( 112 l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE))); 113 break; 114 case PROGRESS_MESSAGE_INSTALLING_UPDATE: 115 progress_message.reset(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(Value::CreateStringValue( 121 l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING))); 122 break; 123 case PROGRESS_MESSAGE_FINALIZING: 124 progress_message.reset(Value::CreateStringValue( 125 l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING))); 126 break; 127 default: 128 NOTREACHED(); 129 }; 130 if (progress_message.get()) 131 CallJS("setProgressMessage", *progress_message); 132 } 133 134 void UpdateScreenHandler::ShowCurtain(bool visible) { 135 CallJS("showUpdateCurtain", visible); 136 } 137 138 void UpdateScreenHandler::RegisterMessages() { 139 #if !defined(OFFICIAL_BUILD) 140 AddCallback("cancelUpdate", &UpdateScreenHandler::HandleUpdateCancel); 141 #endif 142 } 143 144 void UpdateScreenHandler::OnConnectToNetworkRequested( 145 const std::string& service_path) { 146 if (screen_) 147 screen_->OnConnectToNetworkRequested(service_path); 148 } 149 150 #if !defined(OFFICIAL_BUILD) 151 void UpdateScreenHandler::HandleUpdateCancel() { 152 screen_->CancelUpdate(); 153 } 154 #endif 155 156 } // namespace chromeos 157