1 // Copyright (c) 2014 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 Enable developer features screen implementation.
9 login.createScreen('EnableDebuggingScreen', 'debugging', function() {
12 /* Possible UI states of the enable debugging screen. */
27 decorate: function() {
28 $('enable-debugging-help-link').addEventListener('click',
30 chrome.send('enableDebuggingOnLearnMore');
33 var password = $('enable-debugging-password');
34 var password2 = $('enable-debugging-password2');
35 password.addEventListener('input', this.onPasswordChanged_.bind(this));
36 password2.addEventListener('input', this.onPasswordChanged_.bind(this));
37 password.placeholder =
38 loadTimeData.getString('enableDebuggingPasswordLabel');
39 password2.placeholder =
40 loadTimeData.getString('enableDebuggingConfirmPasswordLabel');
44 * Header text of the screen.
48 return loadTimeData.getString('enableDebuggingScreenTitle');
52 * Buttons in oobe wizard's button strip.
53 * @type {array} Array of Buttons.
57 var rootfsRemoveButton = this.ownerDocument.createElement('button');
58 rootfsRemoveButton.id = 'debugging-remove-protection-button';
59 rootfsRemoveButton.textContent =
60 loadTimeData.getString('enableDebuggingRemoveButton');
61 rootfsRemoveButton.addEventListener('click', function(e) {
62 chrome.send('enableDebuggingOnRemoveRootFSProtection');
65 buttons.push(rootfsRemoveButton);
67 var enableButton = this.ownerDocument.createElement('button');
68 enableButton.id = 'debugging-enable-button';
69 enableButton.textContent =
70 loadTimeData.getString('enableDebuggingEnableButton');
71 enableButton.addEventListener('click', function(e) {
72 chrome.send('enableDebuggingOnSetup',
73 [$('enable-debugging-password').value]);
76 buttons.push(enableButton);
78 var cancelButton = this.ownerDocument.createElement('button');
79 cancelButton.id = 'debugging-cancel-button';
80 cancelButton.textContent =
81 loadTimeData.getString('enableDebuggingCancelButton');
82 cancelButton.addEventListener('click', function(e) {
83 chrome.send('enableDebuggingOnCancel');
86 buttons.push(cancelButton);
88 var okButton = this.ownerDocument.createElement('button');
89 okButton.id = 'debugging-ok-button';
90 okButton.textContent =
91 loadTimeData.getString('enableDebuggingOKButton');
92 okButton.addEventListener('click', function(e) {
93 chrome.send('enableDebuggingOnDone');
96 buttons.push(okButton);
102 * Returns a control which should receive an initial focus.
104 get defaultControl() {
105 if (this.state_ == this.UI_STATE.REMOVE_PROTECTION)
106 return $('debugging-remove-protection-button');
107 else if (this.state_ == this.UI_STATE.SETUP)
108 return $('enable-debugging-password');
109 else if (this.state_ == this.UI_STATE.DONE ||
110 this.state_ == this.UI_STATE.ERROR) {
111 return $('debugging-ok-button');
114 return $('debugging-cancel-button');
118 * Cancels the enable debugging screen and drops the user back to the
122 chrome.send('enableDebuggingOnCancel');
126 * Event handler that is invoked just before the screen in shown.
127 * @param {Object} data Screen init payload.
129 onBeforeShow: function(data) {
130 this.setDialogView_(this.UI_STATE.NONE);
133 onPasswordChanged_: function() {
134 var enableButton = $('debugging-enable-button');
135 var password = $('enable-debugging-password');
136 var password2 = $('enable-debugging-password2');
137 var pwd = password.value;
138 var pwd2 = password2.value;
139 enableButton.disabled = !((pwd.length == 0 && pwd2.length == 0) ||
140 (pwd == pwd2 && pwd.length >= 4));
144 * Sets css style for corresponding state of the screen.
145 * @param {number} state.
148 setDialogView_: function(state) {
150 this.classList.toggle('remove-protection-view',
151 state == this.UI_STATE.REMOVE_PROTECTION);
152 this.classList.toggle('setup-view', state == this.UI_STATE.SETUP);
153 this.classList.toggle('wait-view', state == this.UI_STATE.WAIT);
154 this.classList.toggle('done-view', state == this.UI_STATE.DONE);
155 this.classList.toggle('error-view', state == this.UI_STATE.ERROR);
156 this.defaultControl.focus();
158 if (Oobe.getInstance().currentScreen === this)
159 Oobe.getInstance().updateScreenSize(this);
162 updateState: function(state) {
163 this.setDialogView_(state);