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.
6 * @fileoverview Oobe update screen implementation.
9 login.createScreen('UpdateScreen', 'update', function() {
10 var USER_ACTION_CANCEL_UPDATE_SHORTCUT = 'cancel-update';
11 var CONTEXT_KEY_TIME_LEFT_SEC = 'time-left-sec';
12 var CONTEXT_KEY_SHOW_TIME_LEFT = 'show-time-left';
13 var CONTEXT_KEY_UPDATE_MESSAGE = 'update-msg';
14 var CONTEXT_KEY_SHOW_CURTAIN = 'show-curtain';
15 var CONTEXT_KEY_SHOW_PROGRESS_MESSAGE = 'show-progress-msg';
16 var CONTEXT_KEY_PROGRESS = 'progress';
17 var CONTEXT_KEY_PROGRESS_MESSAGE = 'progress-msg';
18 var CONTEXT_KEY_CANCEL_UPDATE_SHORTCUT_ENABLED = 'cancel-update-enabled';
24 decorate: function() {
27 this.context.addObserver(CONTEXT_KEY_TIME_LEFT_SEC,
28 function(time_left_sec) {
29 self.setEstimatedTimeLeft(time_left_sec);
31 this.context.addObserver(CONTEXT_KEY_SHOW_TIME_LEFT,
32 function(show_time_left) {
33 self.showEstimatedTimeLeft(show_time_left);
35 this.context.addObserver(CONTEXT_KEY_UPDATE_MESSAGE,
36 function(update_msg) {
37 self.setUpdateMessage(update_msg);
39 this.context.addObserver(CONTEXT_KEY_SHOW_CURTAIN,
40 function(show_curtain) {
41 self.showUpdateCurtain(show_curtain);
43 this.context.addObserver(CONTEXT_KEY_SHOW_PROGRESS_MESSAGE,
44 function(show_progress_msg) {
45 self.showProgressMessage(show_progress_msg);
47 this.context.addObserver(CONTEXT_KEY_PROGRESS,
49 self.setUpdateProgress(progress);
51 this.context.addObserver(CONTEXT_KEY_PROGRESS_MESSAGE,
52 function(progress_msg) {
53 self.setProgressMessage(progress_msg);
55 this.context.addObserver(CONTEXT_KEY_CANCEL_UPDATE_SHORTCUT_ENABLED,
57 $('update-cancel-hint').hidden = !enabled;
62 * Header text of the screen.
66 return loadTimeData.getString('updateScreenTitle');
73 // It's safe to act on the accelerator even if it's disabled on official
74 // builds, since Chrome will just ignore this user action in that case.
75 var updateCancelHint = $('update-cancel-hint').firstElementChild;
76 updateCancelHint.textContent =
77 loadTimeData.getString('cancelledUpdateMessage');
78 this.send(login.Screen.CALLBACK_USER_ACTED,
79 USER_ACTION_CANCEL_UPDATE_SHORTCUT);
83 * Sets update's progress bar value.
84 * @param {number} progress Percentage of the progress bar.
86 setUpdateProgress: function(progress) {
87 $('update-progress-bar').value = progress;
91 * Shows or hides downloading ETA message.
92 * @param {boolean} visible Are ETA message visible?
94 showEstimatedTimeLeft: function(visible) {
95 $('progress-message').hidden = visible;
96 $('estimated-time-left').hidden = !visible;
100 * Sets estimated time left until download will complete.
101 * @param {number} seconds Time left in seconds.
103 setEstimatedTimeLeft: function(seconds) {
104 var minutes = Math.ceil(seconds / 60);
107 message = loadTimeData.getString('downloadingTimeLeftLong');
108 } else if (minutes > 55) {
109 message = loadTimeData.getString('downloadingTimeLeftStatusOneHour');
110 } else if (minutes > 20) {
111 message = loadTimeData.getStringF('downloadingTimeLeftStatusMinutes',
112 Math.ceil(minutes / 5) * 5);
113 } else if (minutes > 1) {
114 message = loadTimeData.getStringF('downloadingTimeLeftStatusMinutes',
117 message = loadTimeData.getString('downloadingTimeLeftSmall');
119 $('estimated-time-left').textContent =
120 loadTimeData.getStringF('downloading', message);
124 * Shows or hides info message below progress bar.
125 * @param {boolean} visible Are message visible?
127 showProgressMessage: function(visible) {
128 $('estimated-time-left').hidden = visible;
129 $('progress-message').hidden = !visible;
133 * Sets message below progress bar.
134 * @param {string} message Message that should be shown.
136 setProgressMessage: function(message) {
137 $('progress-message').innerText = message;
141 * Sets update message, which is shown above the progress bar.
142 * @param {text} message Message which is shown by the label.
144 setUpdateMessage: function(message) {
145 $('update-upper-label').textContent = message;
149 * Shows or hides update curtain.
150 * @param {boolean} visible Are curtains visible?
152 showUpdateCurtain: function(visible) {
153 $('update-screen-curtain').hidden = !visible;
154 $('update-screen-main').hidden = visible;