OLD | NEW |
(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 enable debugging screen. */ |
| 13 UI_STATE: { |
| 14 ERROR: -1, |
| 15 NONE: 0, |
| 16 REMOVE_PROTECTION: 1, |
| 17 SETUP: 2, |
| 18 WAIT: 3, |
| 19 DONE: 4 |
| 20 }, |
| 21 |
| 22 EXTERNAL_API: [ |
| 23 'updateState' |
| 24 ], |
| 25 |
| 26 /** @override */ |
| 27 decorate: function() { |
| 28 $('enable-debugging-help-link').addEventListener('click', |
| 29 function(event) { |
| 30 chrome.send('enableDebuggingOnLearnMore'); |
| 31 }); |
| 32 |
| 33 var password = $('enable-debugging-password'); |
| 34 var password2 = $('enable-debugging-password2'); |
| 35 $('enable-debugging-password').addEventListener( |
| 36 'input', this.onPasswordChanged_.bind(this)); |
| 37 $('enable-debugging-password2').addEventListener( |
| 38 'input', this.onPasswordChanged_.bind(this)); |
| 39 password.placeholder = |
| 40 loadTimeData.getString('enableDebuggingPasswordLabel'); |
| 41 password2.placeholder = |
| 42 loadTimeData.getString('enableDebuggingConfirmPasswordLabel'); |
| 43 }, |
| 44 |
| 45 /** |
| 46 * Header text of the screen. |
| 47 * @type {string} |
| 48 */ |
| 49 get header() { |
| 50 return loadTimeData.getString('enableDebuggingScreenTitle'); |
| 51 }, |
| 52 |
| 53 /** |
| 54 * Buttons in oobe wizard's button strip. |
| 55 * @type {array} Array of Buttons. |
| 56 */ |
| 57 get buttons() { |
| 58 var buttons = []; |
| 59 var rootfsRemoveButton = this.ownerDocument.createElement('button'); |
| 60 rootfsRemoveButton.id = 'debugging-remove-protection-button'; |
| 61 rootfsRemoveButton.textContent = |
| 62 loadTimeData.getString('enableDebuggingRemoveButton'); |
| 63 rootfsRemoveButton.addEventListener('click', function(e) { |
| 64 chrome.send('enableDebuggingOnRemoveRootFSProtection'); |
| 65 e.stopPropagation(); |
| 66 }); |
| 67 buttons.push(rootfsRemoveButton); |
| 68 |
| 69 var enableButton = this.ownerDocument.createElement('button'); |
| 70 enableButton.id = 'debugging-enable-button'; |
| 71 enableButton.textContent = |
| 72 loadTimeData.getString('enableDebuggingEnableButton'); |
| 73 enableButton.addEventListener('click', function(e) { |
| 74 chrome.send('enableDebuggingOnSetup', |
| 75 [$('enable-debugging-password').value]); |
| 76 e.stopPropagation(); |
| 77 }); |
| 78 buttons.push(enableButton); |
| 79 |
| 80 var cancelButton = this.ownerDocument.createElement('button'); |
| 81 cancelButton.id = 'debugging-cancel-button'; |
| 82 cancelButton.textContent = |
| 83 loadTimeData.getString('enableDebuggingCancelButton'); |
| 84 cancelButton.addEventListener('click', function(e) { |
| 85 chrome.send('enableDebuggingOnCancel'); |
| 86 e.stopPropagation(); |
| 87 }); |
| 88 buttons.push(cancelButton); |
| 89 |
| 90 var okButton = this.ownerDocument.createElement('button'); |
| 91 okButton.id = 'debugging-ok-button'; |
| 92 okButton.textContent = |
| 93 loadTimeData.getString('enableDebuggingOKButton'); |
| 94 okButton.addEventListener('click', function(e) { |
| 95 chrome.send('enableDebuggingOnDone'); |
| 96 e.stopPropagation(); |
| 97 }); |
| 98 buttons.push(okButton); |
| 99 |
| 100 return buttons; |
| 101 }, |
| 102 |
| 103 /** |
| 104 * Returns a control which should receive an initial focus. |
| 105 */ |
| 106 get defaultControl() { |
| 107 if (this.state_ == this.UI_STATE.REMOVE_PROTECTION) |
| 108 return $('debugging-remove-protection-button'); |
| 109 else if (this.state_ == this.UI_STATE.SETUP) |
| 110 return $('enable-debugging-password'); |
| 111 else if (this.state_ == this.UI_STATE.DONE) |
| 112 return $('debugging-ok-button'); |
| 113 |
| 114 return $('debugging-cancel-button'); |
| 115 }, |
| 116 |
| 117 /** |
| 118 * Cancels the enable debugging screen and drops the user back to the |
| 119 * network settings. |
| 120 */ |
| 121 cancel: function() { |
| 122 chrome.send('enableDebuggingOnCancel'); |
| 123 }, |
| 124 |
| 125 /** |
| 126 * Event handler that is invoked just before the screen in shown. |
| 127 * @param {Object} data Screen init payload. |
| 128 */ |
| 129 onBeforeShow: function(data) { |
| 130 this.setDialogView_(this.UI_STATE.NONE); |
| 131 |
| 132 if (data === undefined) |
| 133 return; |
| 134 |
| 135 // TODO(zelidrag): http://crbug.com/431950, show the link once we |
| 136 // create HC article. |
| 137 // if (!('isOfficialBuild' in data && data['isOfficialBuild'])) |
| 138 // $('enable-debugging-help-link').hidden = true; |
| 139 $('enable-debugging-help-link').hidden = true; |
| 140 }, |
| 141 |
| 142 onPasswordChanged_: function() { |
| 143 var enableButton = $('debugging-enable-button'); |
| 144 var password = $('enable-debugging-password'); |
| 145 var password2 = $('enable-debugging-password2'); |
| 146 var pwd = password.value; |
| 147 var pwd2 = password2.value; |
| 148 enableButton.disabled = !((pwd.length == 0 && pwd2.length == 0) || |
| 149 (pwd == pwd2 && pwd.length >= 4)); |
| 150 }, |
| 151 |
| 152 /** |
| 153 * Sets css style for corresponding state of the screen. |
| 154 * @param {number} state. |
| 155 * @private |
| 156 */ |
| 157 setDialogView_: function(state) { |
| 158 this.state_ = state; |
| 159 this.classList.toggle('remove-protection-view', |
| 160 state == this.UI_STATE.REMOVE_PROTECTION); |
| 161 this.classList.toggle('setup-view', state == this.UI_STATE.SETUP); |
| 162 this.classList.toggle('wait-view', state == this.UI_STATE.WAIT); |
| 163 this.classList.toggle('done-view', state == this.UI_STATE.DONE); |
| 164 this.classList.toggle('error-view', state == this.UI_STATE.ERROR); |
| 165 }, |
| 166 |
| 167 updateState: function(state) { |
| 168 this.setDialogView_(state); |
| 169 } |
| 170 }; |
| 171 }); |
OLD | NEW |