Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / login / oobe_screen_reset.js
blob874f8e3165f01d69302895c97188cbe95ecf9dc7
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.
5 /**
6  * @fileoverview Device reset screen implementation.
7  */
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';
22   return {
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',
31     },
33     RESET_SCREEN_STATE: {
34       RESTART_REQUIRED: 0,
35       REVERT_PROMISE: 1,
36       POWERWASH_PROPOSAL: 2,  // supports 2 ui-states
37       ERROR: 3,
38     },
41     /** @override */
42     decorate: function() {
43       var self = this;
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                              });
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       );
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     },
110     /**
111      * Header text of the screen.
112      * @type {string}
113      */
114     get header() {
115       return loadTimeData.getString('resetScreenTitle');
116     },
118     /**
119      * Buttons in oobe wizard's button strip.
120      * @type {array} Array of Buttons.
121      */
122     get buttons() {
123       var 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,
129                                event: 'click'
130                              });
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,
140                                event: 'click'
141                              });
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,
149                                event: 'click'
150                              });
151       buttons.push(cancelButton);
153       return buttons;
154     },
156     /**
157      * Returns a control which should receive an initial focus.
158      */
159     get defaultControl() {
160       // choose
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');
168     },
170     /**
171      * Cancels the reset and drops the user back to the login screen.
172      */
173     cancel: function() {
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);
177         return;
178       }
179       this.send(login.Screen.CALLBACK_USER_ACTED, USER_ACTION_CANCEL_RESET);
180     },
182     /**
183      * Event handler that is invoked just before the screen in shown.
184      * @param {Object} data Screen init payload.
185      */
186     onBeforeShow: function(data) {
187     },
189     /**
190       * Sets css style for corresponding state of the screen.
191       * @private
192       */
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);
214     },
216     setRollbackOptionView: function() {
217       if (this.context.get(CONTEXT_KEY_IS_CONFIRMATIONAL_VIEW, false))
218         return;
219       if (this.context.get(CONTEXT_KEY_SCREEN_STATE) !=
220           this.RESET_SCREEN_STATE.POWERWASH_PROPOSAL)
221         return;
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;
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     }
237   };