OLD | NEW |
---|---|
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 CONTEXT_KEY_ROLLBACK_AVAILABLE = 'rollback-available'; | |
15 var CONTEXT_KEY_ROLLBACK_CHECKED = 'rollback-checked'; | |
16 var CONTEXT_KEY_IS_OFFICIAL_BUILD = 'is-official-build'; | |
17 var CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW = 'is-confirmational-view'; | |
18 var CONTEXT_KEY_SCREEN_STATE = 'screen-state'; | |
19 | |
10 return { | 20 return { |
11 | 21 |
12 /* Possible UI states of the reset screen. */ | 22 /* Possible UI states of the reset screen. */ |
13 RESET_SCREEN_UI_STATE: { | 23 RESET_SCREEN_UI_STATE: { |
14 REVERT_PROMISE: 'ui-state-revert-promise', | 24 REVERT_PROMISE: 'ui-state-revert-promise', |
15 RESTART_REQUIRED: 'ui-state-restart-required', | 25 RESTART_REQUIRED: 'ui-state-restart-required', |
16 POWERWASH_PROPOSAL: 'ui-state-powerwash-proposal', | 26 POWERWASH_PROPOSAL: 'ui-state-powerwash-proposal', |
17 ROLLBACK_PROPOSAL: 'ui-state-rollback-proposal' | 27 ROLLBACK_PROPOSAL: 'ui-state-rollback-proposal', |
28 ERROR: 'ui-state-error', | |
18 }, | 29 }, |
19 | 30 |
20 EXTERNAL_API: [ | 31 RESET_SCREEN_STATE: { |
21 'hideRollbackOption', | 32 RESTART_REQUIRED: 0, |
22 'showRollbackOption', | 33 REVERT_PROMISE: 1, |
23 'updateViewOnRollbackCall' | 34 POWERWASH_PROPOSAL: 2, // supports 2 ui-states |
24 ], | 35 ERROR: 3, |
36 }, | |
37 | |
25 | 38 |
26 /** @override */ | 39 /** @override */ |
27 decorate: function() { | 40 decorate: function() { |
41 var self = this; | |
42 | |
28 $('powerwash-help-link').addEventListener('click', function(event) { | 43 $('powerwash-help-link').addEventListener('click', function(event) { |
dzhioev (left Google)
2015/02/11 12:38:29
this.declareUserAction($('powerwash-help-link'),
merkulova
2015/02/11 15:07:17
Done.
| |
29 chrome.send('resetOnLearnMore'); | 44 self.send(login.Screen.CALLBACK_USER_ACTED, |
45 USER_ACTION_LEARN_MORE_PRESSED); | |
30 }); | 46 }); |
47 | |
48 this.context.addObserver( | |
49 CONTEXT_KEY_SCREEN_STATE, | |
50 function(state) { | |
51 if (state == self.RESET_SCREEN_STATE.RESTART_REQUIRED) | |
52 self.ui_state = self.RESET_SCREEN_UI_STATE.RESTART_REQUIRED; | |
53 if (state == self.RESET_SCREEN_STATE.REVERT_PROMISE) | |
54 self.ui_state = self.RESET_SCREEN_UI_STATE.REVERT_PROMISE; | |
55 else if (state == self.RESET_SCREEN_STATE.POWERWASH_PROPOSAL) | |
56 self.ui_state = self.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL; | |
57 self.setDialogView_(); | |
58 if (state == self.RESET_SCREEN_STATE.REVERT_PROMISE) { | |
59 announceAccessibleMessage( | |
60 loadTimeData.getString('resetRevertSpinnerMessage')); | |
61 } | |
62 } | |
63 ); | |
64 | |
65 this.context.addObserver( | |
66 CONTEXT_KEY_IS_OFFICIAL_BUILD, | |
67 function(isOfficial) { | |
68 $('powerwash-help-link').setAttribute('hidden', !isOfficial); | |
69 } | |
70 ); | |
71 this.context.addObserver( | |
72 CONTEXT_KEY_ROLLBACK_CHECKED, | |
73 function(rollbackChecked) { | |
74 self.setRollbackOptionView(); | |
75 } | |
76 ); | |
77 this.context.addObserver( | |
78 CONTEXT_KEY_ROLLBACK_AVAILABLE, | |
79 function(rollbackAvailable) { | |
80 self.setRollbackOptionView(); | |
81 } | |
82 ); | |
31 }, | 83 }, |
32 | 84 |
33 /** | 85 /** |
34 * Header text of the screen. | 86 * Header text of the screen. |
35 * @type {string} | 87 * @type {string} |
36 */ | 88 */ |
37 get header() { | 89 get header() { |
38 return loadTimeData.getString('resetScreenTitle'); | 90 return loadTimeData.getString('resetScreenTitle'); |
39 }, | 91 }, |
40 | 92 |
41 /** | 93 /** |
42 * Buttons in oobe wizard's button strip. | 94 * Buttons in oobe wizard's button strip. |
43 * @type {array} Array of Buttons. | 95 * @type {array} Array of Buttons. |
44 */ | 96 */ |
45 get buttons() { | 97 get buttons() { |
98 var self = this; | |
46 var buttons = []; | 99 var buttons = []; |
47 var restartButton = this.ownerDocument.createElement('button'); | 100 var restartButton = this.ownerDocument.createElement('button'); |
48 restartButton.id = 'reset-restart-button'; | 101 restartButton.id = 'reset-restart-button'; |
49 restartButton.textContent = loadTimeData.getString('resetButtonRestart'); | 102 restartButton.textContent = loadTimeData.getString('resetButtonRestart'); |
50 restartButton.addEventListener('click', function(e) { | 103 restartButton.addEventListener('click', function(e) { |
dzhioev (left Google)
2015/02/11 12:38:29
Use declareUserAction
merkulova
2015/02/11 15:07:17
Done.
| |
51 chrome.send('restartOnReset'); | 104 self.send(login.Screen.CALLBACK_USER_ACTED, |
105 USER_ACTION_RESTART_PRESSED); | |
52 e.stopPropagation(); | 106 e.stopPropagation(); |
53 }); | 107 }); |
54 buttons.push(restartButton); | 108 buttons.push(restartButton); |
55 | 109 |
56 // Button that leads to confirmation pop-up dialog. | 110 // Button that leads to confirmation pop-up dialog. |
57 var toConfirmButton = this.ownerDocument.createElement('button'); | 111 var toConfirmButton = this.ownerDocument.createElement('button'); |
58 toConfirmButton.id = 'reset-toconfirm-button'; | 112 toConfirmButton.id = 'reset-toconfirm-button'; |
59 toConfirmButton.textContent = | 113 toConfirmButton.textContent = |
60 loadTimeData.getString('resetButtonPowerwash'); | 114 loadTimeData.getString('resetButtonPowerwash'); |
61 toConfirmButton.addEventListener('click', function(e) { | 115 toConfirmButton.addEventListener('click', function(e) { |
62 // change view to confirmational | 116 // change view to confirmational |
63 reset.ConfirmResetOverlay.getInstance().initializePage(); | 117 reset.ConfirmResetOverlay.getInstance().initializePage(); |
64 | 118 |
65 var resetScreen = $('reset'); | 119 self.context.set(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, true); |
dzhioev (left Google)
2015/02/11 12:38:29
This should be done on C++ side as a reaction on U
merkulova
2015/02/11 15:07:17
Done.
dzhioev (left Google)
2015/02/12 12:51:58
Nothing has changed.
merkulova
2015/02/12 13:37:37
Sorry, missed the change.
| |
66 resetScreen.isConfirmational = true; | 120 self.commitContextChanges(); |
67 chrome.send('showConfirmationOnReset'); | 121 self.send(login.Screen.CALLBACK_USER_ACTED, |
122 USER_ACTION_SHOW_CONFIRMATION); | |
68 e.stopPropagation(); | 123 e.stopPropagation(); |
69 }); | 124 }); |
70 buttons.push(toConfirmButton); | 125 buttons.push(toConfirmButton); |
71 | 126 |
72 var cancelButton = this.ownerDocument.createElement('button'); | 127 var cancelButton = this.ownerDocument.createElement('button'); |
73 cancelButton.id = 'reset-cancel-button'; | 128 cancelButton.id = 'reset-cancel-button'; |
74 cancelButton.textContent = loadTimeData.getString('cancelButton'); | 129 cancelButton.textContent = loadTimeData.getString('cancelButton'); |
dzhioev (left Google)
2015/02/11 12:38:29
Use declareUserAction
merkulova
2015/02/11 15:07:17
Done.
| |
75 cancelButton.addEventListener('click', function(e) { | 130 cancelButton.addEventListener('click', function(e) { |
76 chrome.send('cancelOnReset'); | 131 self.send(login.Screen.CALLBACK_USER_ACTED, USER_ACTION_CANCEL_RESET); |
77 e.stopPropagation(); | 132 e.stopPropagation(); |
78 }); | 133 }); |
79 buttons.push(cancelButton); | 134 buttons.push(cancelButton); |
80 | 135 |
81 return buttons; | 136 return buttons; |
82 }, | 137 }, |
83 | 138 |
84 /** | 139 /** |
85 * Returns a control which should receive an initial focus. | 140 * Returns a control which should receive an initial focus. |
86 */ | 141 */ |
87 get defaultControl() { | 142 get defaultControl() { |
88 // choose | 143 // choose |
89 if (this.needRestart) | 144 if (this.context.get(CONTEXT_KEY_SCREEN_STATE, |
145 this.RESET_SCREEN_STATE.RESTART_REQUIRED) == | |
146 this.RESET_SCREEN_STATE.RESTART_REQUIRED) | |
90 return $('reset-restart-button'); | 147 return $('reset-restart-button'); |
91 if (this.isConfirmational) | 148 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false)) |
92 return $('reset-confirm-commit'); | 149 return $('reset-confirm-commit'); |
93 return $('reset-toconfirm-button'); | 150 return $('reset-toconfirm-button'); |
94 }, | 151 }, |
95 | 152 |
96 /** | 153 /** |
97 * Cancels the reset and drops the user back to the login screen. | 154 * Cancels the reset and drops the user back to the login screen. |
98 */ | 155 */ |
99 cancel: function() { | 156 cancel: function() { |
100 if (this.isConfirmational) { | 157 if (this.isConfirmational) { |
101 reset.ConfirmResetOverlay.getInstance().handleDismiss_(); | 158 reset.ConfirmResetOverlay.getInstance().handleDismiss_(); |
102 return; | 159 return; |
103 } | 160 } |
104 chrome.send('cancelOnReset'); | 161 this.send(login.Screen.CALLBACK_USER_ACTED, USER_ACTION_CANCEL_RESET); |
105 }, | 162 }, |
106 | 163 |
107 /** | 164 /** |
108 * Event handler that is invoked just before the screen in shown. | 165 * Event handler that is invoked just before the screen in shown. |
109 * @param {Object} data Screen init payload. | 166 * @param {Object} data Screen init payload. |
110 */ | 167 */ |
111 onBeforeShow: function(data) { | 168 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 } | |
133 }, | 169 }, |
134 | 170 |
135 /** | 171 /** |
136 * Sets css style for corresponding state of the screen. | 172 * Sets css style for corresponding state of the screen. |
137 * @param {string} state. | |
138 * @private | 173 * @private |
139 */ | 174 */ |
140 setDialogView_: function(state) { | 175 setDialogView_: function(state) { |
176 state = this.ui_state; | |
141 var resetOverlay = $('reset-confirm-overlay'); | 177 var resetOverlay = $('reset-confirm-overlay'); |
142 this.classList.remove('revert-promise-view'); | 178 this.classList.toggle( |
143 this.classList.remove('restart-required-view'); | 179 'revert-promise-view', |
144 this.classList.remove('powerwash-proposal-view'); | 180 state == this.RESET_SCREEN_UI_STATE.REVERT_PROMISE); |
145 this.classList.remove('rollback-proposal-view'); | 181 this.classList.toggle( |
146 resetOverlay.classList.remove('powerwash-proposal-view'); | 182 'restart-required-view', |
147 resetOverlay.classList.remove('rollback-proposal-view'); | 183 state == this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED); |
148 if (state == this.RESET_SCREEN_UI_STATE.REVERT_PROMISE) { | 184 this.classList.toggle( |
149 this.classList.add('revert-promise-view'); | 185 'powerwash-proposal-view', |
150 } else if (state == this.RESET_SCREEN_UI_STATE.RESTART_REQUIRED) { | 186 state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL); |
151 this.classList.add('restart-required-view'); | 187 resetOverlay.classList.toggle( |
152 } else if (state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL) { | 188 'powerwash-proposal-view', |
153 this.classList.add('powerwash-proposal-view'); | 189 state == this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL); |
154 resetOverlay.classList.add('powerwash-proposal-view'); | 190 this.classList.toggle( |
155 } else if (state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL) { | 191 'rollback-proposal-view', |
156 this.classList.add('rollback-proposal-view'); | 192 state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL); |
157 resetOverlay.classList.add('rollback-proposal-view'); | 193 resetOverlay.classList.toggle( |
158 } else { // error | 194 'rollback-proposal-view', |
159 console.error('State ' + state + ' is not supported by setDialogView.'); | 195 state == this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL); |
160 } | |
161 }, | 196 }, |
162 | 197 |
163 updateViewOnRollbackCall: function() { | 198 setRollbackOptionView: function() { |
164 this.setDialogView_(this.RESET_SCREEN_UI_STATE.REVERT_PROMISE); | 199 if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false)) |
165 announceAccessibleMessage( | |
166 loadTimeData.getString('resetRevertSpinnerMessage')); | |
167 }, | |
168 | |
169 showRollbackOption: function() { | |
170 if (this.rollbackChecked || this.isConfirmational) | |
171 return; | 200 return; |
172 $('reset-toconfirm-button').textContent = loadTimeData.getString( | 201 if (this.context.get(CONTEXT_KEY_SCREEN_STATE) != |
173 'resetButtonPowerwashAndRollback'); | 202 this.RESET_SCREEN_STATE.POWERWASH_PROPOSAL) |
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) | |
180 return; | 203 return; |
181 | 204 |
182 $('reset-toconfirm-button').textContent = loadTimeData.getString( | 205 if (this.context.get(CONTEXT_KEY_ROLLBACK_AVAILABLE, false) && |
183 'resetButtonPowerwash'); | 206 this.context.get(CONTEXT_KEY_ROLLBACK_CHECKED, false)) { |
184 this.setDialogView_(this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL); | 207 // show rollback option |
185 this.rollbackChecked = false; | 208 $('reset-toconfirm-button').textContent = loadTimeData.getString( |
209 'resetButtonPowerwashAndRollback'); | |
210 this.ui_state = this.RESET_SCREEN_UI_STATE.ROLLBACK_PROPOSAL; | |
211 } else { | |
212 // hide rollback option | |
213 $('reset-toconfirm-button').textContent = loadTimeData.getString( | |
214 'resetButtonPowerwash'); | |
215 this.ui_state = this.RESET_SCREEN_UI_STATE.POWERWASH_PROPOSAL; | |
216 } | |
217 this.setDialogView_(); | |
186 } | 218 } |
187 }; | 219 }; |
188 }); | 220 }); |
OLD | NEW |