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