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 Device reset screen implementation.
9 login.createScreen('ResetScreen', 'reset', function() {
10 var USER_ACTION_CANCEL_RESET = 'cancel-reset';
11 var USER_ACTION_RESTART_PRESSED = 'restart-pressed';
12 var USER_ACTION_LEARN_MORE_PRESSED = 'learn-more-link';
13 var USER_ACTION_SHOW_CONFIRMATION = 'show-confirmation';
14 var USER_ACTION_POWERWASH_PRESSED = 'powerwash-pressed';
15 var USER_ACTION_RESET_CONFIRM_DISMISSED = 'reset-confirm-dismissed';
16 var CONTEXT_KEY_ROLLBACK_AVAILABLE = 'rollback-available';
17 var CONTEXT_KEY_ROLLBACK_CHECKED = 'rollback-checked';
18 var CONTEXT_KEY_IS_OFFICIAL_BUILD = 'is-official-build';
19 var CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW = 'is-confirmational-view';
20 var CONTEXT_KEY_SCREEN_STATE = 'screen-state';
24 /* Possible UI states of the reset screen. */
25 RESET_SCREEN_UI_STATE: {
26 REVERT_PROMISE: 'ui-state-revert-promise',
27 RESTART_REQUIRED: 'ui-state-restart-required',
28 POWERWASH_PROPOSAL: 'ui-state-powerwash-proposal',
29 ROLLBACK_PROPOSAL: 'ui-state-rollback-proposal',
30 ERROR: 'ui-state-error',
36 POWERWASH_PROPOSAL: 2, // supports 2 ui-states
42 decorate: function() {
45 this.declareUserAction($('powerwash-help-link'),
46 { action_id: USER_ACTION_LEARN_MORE_PRESSED,
49 this.declareUserAction($('reset-confirm-dismiss'),
50 { action_id: USER_ACTION_RESET_CONFIRM_DISMISSED,
53 this.declareUserAction($('reset-confirm-commit'),
54 { action_id: USER_ACTION_POWERWASH_PRESSED,
58 this.context.addObserver(
59 CONTEXT_KEY_SCREEN_STATE,
61 if (state == self.RESET_SCREEN_STATE.RESTART_REQUIRED)
62 self.ui_state = self.RESET_SCREEN_UI_STATE.RESTART_REQUIRED;
63 if (state == self.RESET_SCREEN_STATE.REVERT_PROMISE)
64 self.ui_state = self.RESET_SCREEN_UI_STATE.REVERT_PROMISE;
65 else if (state == self.RESET_SCREEN_STATE.POWERWASH_PROPOSAL)
66 self.ui_state = self.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL;
67 self.setDialogView_();
68 if (state == self.RESET_SCREEN_STATE.REVERT_PROMISE) {
69 announceAccessibleMessage(
70 loadTimeData.getString('resetRevertSpinnerMessage'));
75 this.context.addObserver(
76 CONTEXT_KEY_IS_OFFICIAL_BUILD,
77 function(isOfficial) {
78 $('powerwash-help-link').setAttribute('hidden', !isOfficial);
81 this.context.addObserver(
82 CONTEXT_KEY_ROLLBACK_CHECKED,
83 function(rollbackChecked) {
84 self.setRollbackOptionView();
87 this.context.addObserver(
88 CONTEXT_KEY_ROLLBACK_AVAILABLE,
89 function(rollbackAvailable) {
90 self.setRollbackOptionView();
93 this.context.addObserver(
94 CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW,
95 function(is_confirmational) {
96 if (is_confirmational) {
97 console.log(self.context.get(CONTEXT_KEY_SCREEN_STATE, 0));
98 if (self.context.get(CONTEXT_KEY_SCREEN_STATE, 0) !=
99 self.RESET_SCREEN_STATE.POWERWASH_PROPOSAL)
102 reset.ConfirmResetOverlay.getInstance().initializePage();
104 $('overlay-reset').setAttribute('hidden', true);
111 * Header text of the screen.
115 return loadTimeData.getString('resetScreenTitle');
119 * Buttons in oobe wizard's button strip.
120 * @type {array} Array of Buttons.
124 var restartButton = this.ownerDocument.createElement('button');
125 restartButton.id = 'reset-restart-button';
126 restartButton.textContent = loadTimeData.getString('resetButtonRestart');
127 this.declareUserAction(restartButton,
128 { action_id: USER_ACTION_RESTART_PRESSED,
131 buttons.push(restartButton);
133 // Button that leads to confirmation pop-up dialog.
134 var toConfirmButton = this.ownerDocument.createElement('button');
135 toConfirmButton.id = 'reset-toconfirm-button';
136 toConfirmButton.textContent =
137 loadTimeData.getString('resetButtonPowerwash');
138 this.declareUserAction(toConfirmButton,
139 { action_id: USER_ACTION_SHOW_CONFIRMATION,
142 buttons.push(toConfirmButton);
144 var cancelButton = this.ownerDocument.createElement('button');
145 cancelButton.id = 'reset-cancel-button';
146 cancelButton.textContent = loadTimeData.getString('cancelButton');
147 this.declareUserAction(cancelButton,
148 { action_id: USER_ACTION_CANCEL_RESET,
151 buttons.push(cancelButton);
157 * Returns a control which should receive an initial focus.
159 get defaultControl() {
161 if (this.context.get(CONTEXT_KEY_SCREEN_STATE,
162 this.RESET_SCREEN_STATE.RESTART_REQUIRED) ==
163 this.RESET_SCREEN_STATE.RESTART_REQUIRED)
164 return $('reset-restart-button');
165 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false))
166 return $('reset-confirm-commit');
167 return $('reset-toconfirm-button');
171 * Cancels the reset and drops the user back to the login screen.
174 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false)) {
175 $('reset').send(login.Screen.CALLBACK_USER_ACTED,
176 USER_ACTION_RESET_CONFIRM_DISMISSED);
179 this.send(login.Screen.CALLBACK_USER_ACTED, USER_ACTION_CANCEL_RESET);
183 * Event handler that is invoked just before the screen in shown.
184 * @param {Object} data Screen init payload.
186 onBeforeShow: function(data) {
190 * Sets css style for corresponding state of the screen.
193 setDialogView_: function(state) {
194 state = this.ui_state;
195 var resetOverlay = $('reset-confirm-overlay');
196 this.classList.toggle(
197 'revert-promise-view',
198 state == this.RESET_SCREEN_UI_STATE.REVERT_PROMISE);
199 this.classList.toggle(
200 'restart-required-view',
201 state == this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED);
202 this.classList.toggle(
203 'powerwash-proposal-view',
204 state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL);
205 resetOverlay.classList.toggle(
206 'powerwash-proposal-view',
207 state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL);
208 this.classList.toggle(
209 'rollback-proposal-view',
210 state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL);
211 resetOverlay.classList.toggle(
212 'rollback-proposal-view',
213 state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL);
216 setRollbackOptionView: function() {
217 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false))
219 if (this.context.get(CONTEXT_KEY_SCREEN_STATE) !=
220 this.RESET_SCREEN_STATE.POWERWASH_PROPOSAL)
223 if (this.context.get(CONTEXT_KEY_ROLLBACK_AVAILABLE, false) &&
224 this.context.get(CONTEXT_KEY_ROLLBACK_CHECKED, false)) {
225 // show rollback option
226 $('reset-toconfirm-button').textContent = loadTimeData.getString(
227 'resetButtonPowerwashAndRollback');
228 this.ui_state = this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL;
230 // hide rollback option
231 $('reset-toconfirm-button').textContent = loadTimeData.getString(
232 'resetButtonPowerwash');
233 this.ui_state = this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL;
235 this.setDialogView_();