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

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

Issue 539273002: Added UI to enable debugging features on CrOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
(Empty)
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.
4
5 /**
6 * @fileoverview Enable developer features screen implementation.
7 */
8
9 login.createScreen('EnableDebuggingScreen', 'debugging', function() {
10 return {
11
12 /* Possible UI states of the reset screen. */
13 UI_STATE: {
14 ERROR: -1,
15 REMOVE_PROTECTION: 1,
16 SETUP: 2,
17 WAIT: 3,
18 DONE: 4
19 },
20
21 EXTERNAL_API: [
22 'updateState'
23 ],
24
25 /** @override */
26 decorate: function() {
27 $('enable-debugging-help-link').addEventListener('click',
28 function(event) {
29 chrome.send('enableDebuggingOnLearnMore');
30 });
31
32 var password = $('enable-debugging-password');
33 var password2 = $('enable-debugging-password2');
34 $('enable-debugging-password').addEventListener(
35 'keyup', this.onPasswordChanged_.bind(this));
xiyuan 2014/10/30 03:52:08 nit: There is a 'input' event for <input> and <tex
zel 2014/10/31 01:22:26 Done.
36 $('enable-debugging-password2').addEventListener(
37 'keyup', this.onPasswordChanged_.bind(this));
38 },
39
40 /**
41 * Header text of the screen.
42 * @type {string}
43 */
44 get header() {
45 return loadTimeData.getString('enableDebuggingScreenTitle');
46 },
47
48 /**
49 * Buttons in oobe wizard's button strip.
50 * @type {array} Array of Buttons.
51 */
52 get buttons() {
53 var buttons = [];
54 var rootfsRemoveButton = this.ownerDocument.createElement('button');
55 rootfsRemoveButton.id = 'debugging-remove-protection-button';
56 rootfsRemoveButton.textContent =
57 loadTimeData.getString('enableDebuggingRemoveButton');
58 rootfsRemoveButton.addEventListener('click', function(e) {
59 chrome.send('enableDebuggingOnRemoveRootFSProtection');
60 e.stopPropagation();
61 });
62 buttons.push(rootfsRemoveButton);
63
64 var enableButton = this.ownerDocument.createElement('button');
65 enableButton.id = 'debugging-enable-button';
66 enableButton.textContent =
67 loadTimeData.getString('enableDebuggingEnableButton');
68 enableButton.addEventListener('click', function(e) {
69 chrome.send('enableDebuggingOnSetup',
70 [$('enable-debugging-password').value]);
71 e.stopPropagation();
72 });
73 buttons.push(enableButton);
74
75 var cancelButton = this.ownerDocument.createElement('button');
76 cancelButton.id = 'debugging-cancel-button';
77 cancelButton.textContent =
78 loadTimeData.getString('enableDebuggingCancelButton');
79 cancelButton.addEventListener('click', function(e) {
80 chrome.send('enableDebuggingOnCancel');
81 e.stopPropagation();
82 });
83 buttons.push(cancelButton);
84
85 var okButton = this.ownerDocument.createElement('button');
86 okButton.id = 'debugging-ok-button';
87 okButton.textContent =
88 loadTimeData.getString('enableDebuggingOKButton');
89 okButton.addEventListener('click', function(e) {
90 chrome.send('enableDebuggingOnDone');
91 e.stopPropagation();
92 });
93 buttons.push(okButton);
94
95 return buttons;
96 },
97
98 /**
99 * Returns a control which should receive an initial focus.
100 */
101 get defaultControl() {
102 if (this.state_ == this.UI_STATE.REMOVE_PROTECTION)
103 return $('debugging-remove-protection-button');
104 else if (this.state_ == this.UI_STATE.SETUP)
105 return $('enable-debugging-password');
106 else if (this.state_ == this.UI_STATE.DONE)
107 return $('debugging-ok-button');
108
109 return $('debugging-cancel-button');
110 },
111
112 /**
113 * Cancels the reset and drops the user back to the login screen.
114 */
115 cancel: function() {
116 chrome.send('enableDebuggingOnCancel');
117 },
118
119 /**
120 * Event handler that is invoked just before the screen in shown.
121 * @param {Object} data Screen init payload.
122 */
123 onBeforeShow: function(data) {
124 if (data === undefined)
125 return;
126
127 if ('needsRootfsRemoval' in data && data['needsRootfsRemoval']) {
128 this.setDialogView_(this.UI_STATE.REMOVE_PROTECTION);
129 } else {
130 this.setDialogView_(this.UI_STATE.SETUP);
131 }
132
133 if (!('isOfficialBuild' in data && data['isOfficialBuild']))
134 $('enable-debugging-help-link').setAttribute('hidden', true);
xiyuan 2014/10/30 03:52:08 nit: we can just do $('enable-debugging-help-link
zel 2014/10/31 01:22:26 Done.
135 },
136
137 onPasswordChanged_: function() {
138 var enableButton = $('debugging-enable-button');
139 var password = $('enable-debugging-password');
140 var password2 = $('enable-debugging-password2');
141 var pwd = password.value;
142 var pwd2 = password2.value;
143 enableButton.disabled = !((pwd.length == 0 && pwd2.length == 0) ||
144 (pwd == pwd2 && pwd.length >= 4));
145 },
146
147 /**
148 * Sets css style for corresponding state of the screen.
149 * @param {string} state.
xiyuan 2014/10/30 03:52:08 nit: |state| seems to be an number.
zel 2014/10/31 01:22:26 Done.
150 * @private
151 */
152 setDialogView_: function(state) {
153 this.state_ = state;
154 this.classList.remove('remove-protection-view');
155 this.classList.remove('setup-view');
156 this.classList.remove('wait-view');
157 this.classList.remove('done-view');
158 if (state == this.UI_STATE.REMOVE_PROTECTION) {
159 this.classList.add('remove-protection-view');
160 } else if (state == this.UI_STATE.SETUP) {
161 this.classList.add('setup-view');
162 } else if (state == this.UI_STATE.DONE) {
163 this.classList.add('done-view');
164 } else if (state == this.UI_STATE.WAIT) {
165 this.classList.add('wait-view');
166 } else { // error
167 console.error('State ' + state + ' is not supported by setDialogView.');
168 }
xiyuan 2014/10/30 03:52:08 nit: we could use classList.toggle to simplify a b
zel 2014/10/31 01:22:26 neat. done.
169 },
170
171 updateState: function(state) {
172 this.setDialogView_(state);
173 }
174 };
175 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698