Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/resources/chromeos/login/oobe_screen_reset.js

Issue 928513002: Revert of Reset Screen moved to ScreenContext. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Device reset screen implementation. 6 * @fileoverview Device reset screen implementation.
7 */ 7 */
8 8
9 login.createScreen('ResetScreen', 'reset', function() { 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';
21
22 return { 10 return {
23 11
24 /* Possible UI states of the reset screen. */ 12 /* Possible UI states of the reset screen. */
25 RESET_SCREEN_UI_STATE: { 13 RESET_SCREEN_UI_STATE: {
26 REVERT_PROMISE: 'ui-state-revert-promise', 14 REVERT_PROMISE: 'ui-state-revert-promise',
27 RESTART_REQUIRED: 'ui-state-restart-required', 15 RESTART_REQUIRED: 'ui-state-restart-required',
28 POWERWASH_PROPOSAL: 'ui-state-powerwash-proposal', 16 POWERWASH_PROPOSAL: 'ui-state-powerwash-proposal',
29 ROLLBACK_PROPOSAL: 'ui-state-rollback-proposal', 17 ROLLBACK_PROPOSAL: 'ui-state-rollback-proposal'
30 ERROR: 'ui-state-error',
31 }, 18 },
32 19
33 RESET_SCREEN_STATE: { 20 EXTERNAL_API: [
34 RESTART_REQUIRED: 0, 21 'hideRollbackOption',
35 REVERT_PROMISE: 1, 22 'showRollbackOption',
36 POWERWASH_PROPOSAL: 2, // supports 2 ui-states 23 'updateViewOnRollbackCall'
37 ERROR: 3, 24 ],
38 },
39
40 25
41 /** @override */ 26 /** @override */
42 decorate: function() { 27 decorate: function() {
43 var self = this; 28 $('powerwash-help-link').addEventListener('click', function(event) {
44 29 chrome.send('resetOnLearnMore');
45 this.declareUserAction($('powerwash-help-link'), 30 });
46 { action_id: USER_ACTION_LEARN_MORE_PRESSED,
47 event: 'click'
48 });
49 this.declareUserAction($('reset-confirm-dismiss'),
50 { action_id: USER_ACTION_RESET_CONFIRM_DISMISSED,
51 event: 'click'
52 });
53 this.declareUserAction($('reset-confirm-commit'),
54 { action_id: USER_ACTION_POWERWASH_PRESSED,
55 event: 'click'
56 });
57
58 this.context.addObserver(
59 CONTEXT_KEY_SCREEN_STATE,
60 function(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'));
71 }
72 }
73 );
74
75 this.context.addObserver(
76 CONTEXT_KEY_IS_OFFICIAL_BUILD,
77 function(isOfficial) {
78 $('powerwash-help-link').setAttribute('hidden', !isOfficial);
79 }
80 );
81 this.context.addObserver(
82 CONTEXT_KEY_ROLLBACK_CHECKED,
83 function(rollbackChecked) {
84 self.setRollbackOptionView();
85 }
86 );
87 this.context.addObserver(
88 CONTEXT_KEY_ROLLBACK_AVAILABLE,
89 function(rollbackAvailable) {
90 self.setRollbackOptionView();
91 }
92 );
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)
100 return;
101 console.log(self);
102 reset.ConfirmResetOverlay.getInstance().initializePage();
103 } else {
104 $('overlay-reset').setAttribute('hidden', true);
105 }
106 }
107 );
108 }, 31 },
109 32
110 /** 33 /**
111 * Header text of the screen. 34 * Header text of the screen.
112 * @type {string} 35 * @type {string}
113 */ 36 */
114 get header() { 37 get header() {
115 return loadTimeData.getString('resetScreenTitle'); 38 return loadTimeData.getString('resetScreenTitle');
116 }, 39 },
117 40
118 /** 41 /**
119 * Buttons in oobe wizard's button strip. 42 * Buttons in oobe wizard's button strip.
120 * @type {array} Array of Buttons. 43 * @type {array} Array of Buttons.
121 */ 44 */
122 get buttons() { 45 get buttons() {
123 var buttons = []; 46 var buttons = [];
124 var restartButton = this.ownerDocument.createElement('button'); 47 var restartButton = this.ownerDocument.createElement('button');
125 restartButton.id = 'reset-restart-button'; 48 restartButton.id = 'reset-restart-button';
126 restartButton.textContent = loadTimeData.getString('resetButtonRestart'); 49 restartButton.textContent = loadTimeData.getString('resetButtonRestart');
127 this.declareUserAction(restartButton, 50 restartButton.addEventListener('click', function(e) {
128 { action_id: USER_ACTION_RESTART_PRESSED, 51 chrome.send('restartOnReset');
129 event: 'click' 52 e.stopPropagation();
130 }); 53 });
131 buttons.push(restartButton); 54 buttons.push(restartButton);
132 55
133 // Button that leads to confirmation pop-up dialog. 56 // Button that leads to confirmation pop-up dialog.
134 var toConfirmButton = this.ownerDocument.createElement('button'); 57 var toConfirmButton = this.ownerDocument.createElement('button');
135 toConfirmButton.id = 'reset-toconfirm-button'; 58 toConfirmButton.id = 'reset-toconfirm-button';
136 toConfirmButton.textContent = 59 toConfirmButton.textContent =
137 loadTimeData.getString('resetButtonPowerwash'); 60 loadTimeData.getString('resetButtonPowerwash');
138 this.declareUserAction(toConfirmButton, 61 toConfirmButton.addEventListener('click', function(e) {
139 { action_id: USER_ACTION_SHOW_CONFIRMATION, 62 // change view to confirmational
140 event: 'click' 63 reset.ConfirmResetOverlay.getInstance().initializePage();
141 }); 64
65 var resetScreen = $('reset');
66 resetScreen.isConfirmational = true;
67 chrome.send('showConfirmationOnReset');
68 e.stopPropagation();
69 });
142 buttons.push(toConfirmButton); 70 buttons.push(toConfirmButton);
143 71
144 var cancelButton = this.ownerDocument.createElement('button'); 72 var cancelButton = this.ownerDocument.createElement('button');
145 cancelButton.id = 'reset-cancel-button'; 73 cancelButton.id = 'reset-cancel-button';
146 cancelButton.textContent = loadTimeData.getString('cancelButton'); 74 cancelButton.textContent = loadTimeData.getString('cancelButton');
147 this.declareUserAction(cancelButton, 75 cancelButton.addEventListener('click', function(e) {
148 { action_id: USER_ACTION_CANCEL_RESET, 76 chrome.send('cancelOnReset');
149 event: 'click' 77 e.stopPropagation();
150 }); 78 });
151 buttons.push(cancelButton); 79 buttons.push(cancelButton);
152 80
153 return buttons; 81 return buttons;
154 }, 82 },
155 83
156 /** 84 /**
157 * Returns a control which should receive an initial focus. 85 * Returns a control which should receive an initial focus.
158 */ 86 */
159 get defaultControl() { 87 get defaultControl() {
160 // choose 88 // choose
161 if (this.context.get(CONTEXT_KEY_SCREEN_STATE, 89 if (this.needRestart)
162 this.RESET_SCREEN_STATE.RESTART_REQUIRED) ==
163 this.RESET_SCREEN_STATE.RESTART_REQUIRED)
164 return $('reset-restart-button'); 90 return $('reset-restart-button');
165 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false)) 91 if (this.isConfirmational)
166 return $('reset-confirm-commit'); 92 return $('reset-confirm-commit');
167 return $('reset-toconfirm-button'); 93 return $('reset-toconfirm-button');
168 }, 94 },
169 95
170 /** 96 /**
171 * Cancels the reset and drops the user back to the login screen. 97 * Cancels the reset and drops the user back to the login screen.
172 */ 98 */
173 cancel: function() { 99 cancel: function() {
174 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false)) { 100 if (this.isConfirmational) {
175 $('reset').send(login.Screen.CALLBACK_USER_ACTED, 101 reset.ConfirmResetOverlay.getInstance().handleDismiss_();
176 USER_ACTION_RESET_CONFIRM_DISMISSED);
177 return; 102 return;
178 } 103 }
179 this.send(login.Screen.CALLBACK_USER_ACTED, USER_ACTION_CANCEL_RESET); 104 chrome.send('cancelOnReset');
180 }, 105 },
181 106
182 /** 107 /**
183 * Event handler that is invoked just before the screen in shown. 108 * Event handler that is invoked just before the screen in shown.
184 * @param {Object} data Screen init payload. 109 * @param {Object} data Screen init payload.
185 */ 110 */
186 onBeforeShow: function(data) { 111 onBeforeShow: function(data) {
112 if (data === undefined)
113 return;
114
115 this.rollbackChecked = false;
116 this.rollbackAvailable = false;
117 this.isConfirmational = false;
118 this.hasLearnMoreLink = false;
119
120 if (!('isOfficialBuild' in data && data['isOfficialBuild']))
121 $('powerwash-help-link').setAttribute('hidden', true);
122
123 if ('rollbackAvailable' in data)
124 this.rollbackAvailable = data['rollbackAvailable'];
125
126 if ('restartRequired' in data && data['restartRequired']) {
127 this.restartRequired = true;
128 this.setDialogView_(this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED);
129 } else {
130 this.restartRequired = false;
131 this.setDialogView_(this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL);
132 }
187 }, 133 },
188 134
189 /** 135 /**
190 * Sets css style for corresponding state of the screen. 136 * Sets css style for corresponding state of the screen.
137 * @param {string} state.
191 * @private 138 * @private
192 */ 139 */
193 setDialogView_: function(state) { 140 setDialogView_: function(state) {
194 state = this.ui_state;
195 var resetOverlay = $('reset-confirm-overlay'); 141 var resetOverlay = $('reset-confirm-overlay');
196 this.classList.toggle( 142 this.classList.remove('revert-promise-view');
197 'revert-promise-view', 143 this.classList.remove('restart-required-view');
198 state == this.RESET_SCREEN_UI_STATE.REVERT_PROMISE); 144 this.classList.remove('powerwash-proposal-view');
199 this.classList.toggle( 145 this.classList.remove('rollback-proposal-view');
200 'restart-required-view', 146 resetOverlay.classList.remove('powerwash-proposal-view');
201 state == this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED); 147 resetOverlay.classList.remove('rollback-proposal-view');
202 this.classList.toggle( 148 if (state == this.RESET_SCREEN_UI_STATE.REVERT_PROMISE) {
203 'powerwash-proposal-view', 149 this.classList.add('revert-promise-view');
204 state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL); 150 } else if (state == this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED) {
205 resetOverlay.classList.toggle( 151 this.classList.add('restart-required-view');
206 'powerwash-proposal-view', 152 } else if (state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL) {
207 state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL); 153 this.classList.add('powerwash-proposal-view');
208 this.classList.toggle( 154 resetOverlay.classList.add('powerwash-proposal-view');
209 'rollback-proposal-view', 155 } else if (state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL) {
210 state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL); 156 this.classList.add('rollback-proposal-view');
211 resetOverlay.classList.toggle( 157 resetOverlay.classList.add('rollback-proposal-view');
212 'rollback-proposal-view', 158 } else { // error
213 state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL); 159 console.error('State ' + state + ' is not supported by setDialogView.');
160 }
214 }, 161 },
215 162
216 setRollbackOptionView: function() { 163 updateViewOnRollbackCall: function() {
217 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false)) 164 this.setDialogView_(this.RESET_SCREEN_UI_STATE.REVERT_PROMISE);
165 announceAccessibleMessage(
166 loadTimeData.getString('resetRevertSpinnerMessage'));
167 },
168
169 showRollbackOption: function() {
170 if (this.rollbackChecked || this.isConfirmational)
218 return; 171 return;
219 if (this.context.get(CONTEXT_KEY_SCREEN_STATE) != 172 $('reset-toconfirm-button').textContent = loadTimeData.getString(
220 this.RESET_SCREEN_STATE.POWERWASH_PROPOSAL) 173 'resetButtonPowerwashAndRollback');
174 this.setDialogView_(this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL);
175 this.rollbackChecked = true;
176 },
177
178 hideRollbackOption: function() {
179 if (!this.rollbackChecked || this.isConfirmational)
221 return; 180 return;
222 181
223 if (this.context.get(CONTEXT_KEY_ROLLBACK_AVAILABLE, false) && 182 $('reset-toconfirm-button').textContent = loadTimeData.getString(
224 this.context.get(CONTEXT_KEY_ROLLBACK_CHECKED, false)) { 183 'resetButtonPowerwash');
225 // show rollback option 184 this.setDialogView_(this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL);
226 $('reset-toconfirm-button').textContent = loadTimeData.getString( 185 this.rollbackChecked = false;
227 'resetButtonPowerwashAndRollback');
228 this.ui_state = this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL;
229 } else {
230 // hide rollback option
231 $('reset-toconfirm-button').textContent = loadTimeData.getString(
232 'resetButtonPowerwash');
233 this.ui_state = this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL;
234 }
235 this.setDialogView_();
236 } 186 }
237 }; 187 };
238 }); 188 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698