OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 cr.define('options', function() { |
| 6 const OptionsPage = options.OptionsPage; |
| 7 |
| 8 /** |
| 9 * The number of milliseconds used for showing a message. |
| 10 * @type {number} |
| 11 */ |
| 12 const MESSAGE_DELAY_MS = 1000; // 1 sec. |
| 13 |
| 14 /** |
| 15 * Encapsulated handling of about page. |
| 16 */ |
| 17 function AboutPage() { |
| 18 OptionsPage.call(this, 'about', templateData.aboutPageTabTitle, |
| 19 'aboutPage'); |
| 20 } |
| 21 |
| 22 cr.addSingletonGetter(AboutPage); |
| 23 |
| 24 AboutPage.prototype = { |
| 25 // Inherit AboutPage from OptionsPage. |
| 26 __proto__: OptionsPage.prototype, |
| 27 |
| 28 /** |
| 29 * The queue is used for updating the status message with delay, like: |
| 30 * [["Check for update...", 1000], ["Chrome OS is up to date", 0]] |
| 31 * @type {!Array.<!Array>} |
| 32 */ |
| 33 statusMessageQueue_: [], |
| 34 |
| 35 /** |
| 36 * True if the status message queue flush started. |
| 37 * @type {boolean} |
| 38 */ |
| 39 statusMessageQueueFlushStarted_: false, |
| 40 |
| 41 /** |
| 42 * The selected release channel. |
| 43 * @type {string} |
| 44 */ |
| 45 selectedChannel_: '', |
| 46 |
| 47 // Initialize AboutPage. |
| 48 initializePage: function() { |
| 49 // Call base class implementation to start preference initialization. |
| 50 OptionsPage.prototype.initializePage.call(this); |
| 51 |
| 52 $('checkNow').onclick = function(event) { |
| 53 chrome.send('CheckNow'); |
| 54 }; |
| 55 |
| 56 $('moreInfoButton').onclick = function(event) { |
| 57 $('aboutPageLessInfo').hidden = true; |
| 58 $('aboutPageMoreInfo').hidden = false; |
| 59 }; |
| 60 |
| 61 if (!AccountsOptions.currentUserIsOwner()) { |
| 62 $('channelSelect').disabled = true; |
| 63 } else { |
| 64 var self = this; |
| 65 $('channelSelect').onchange = function(event) { |
| 66 self.selectedOptionOnChange_(event.target.value); |
| 67 }; |
| 68 } |
| 69 |
| 70 // Notify the handler that the page is ready. |
| 71 chrome.send('PageReady'); |
| 72 }, |
| 73 |
| 74 // Update the Default Browsers section based on the current state. |
| 75 updateOSVersion_: function(versionString) { |
| 76 $('osVersion0').textContent = versionString; |
| 77 $('osVersion1').textContent = versionString; |
| 78 }, |
| 79 |
| 80 updateOSFirmware_: function(firmwareString) { |
| 81 $('osFirmware0').textContent = firmwareString; |
| 82 $('osFirmware1').textContent = firmwareString; |
| 83 }, |
| 84 |
| 85 /** |
| 86 * Updates the status message like "Checking for update...". |
| 87 * @param {string} message The message to be shown. |
| 88 * @param {boolean} insertDelay show the message for a while. |
| 89 * @private |
| 90 */ |
| 91 updateStatus_: function(message, insertDelay) { |
| 92 // Add the message to the queue with delay if needed. |
| 93 // The delay is inserted so users can read the message. |
| 94 var delayMs = insertDelay ? MESSAGE_DELAY_MS : 0; |
| 95 this.statusMessageQueue_.push([message, delayMs]); |
| 96 // Start the periodic flusher if not started. |
| 97 if (this.statusMessageQueueFlushStarted_ == false) { |
| 98 this.flushStatusMessageQueuePeriodically_(); |
| 99 } |
| 100 }, |
| 101 |
| 102 /** |
| 103 * Flushes the status message queue periodically using a timer. |
| 104 * @private |
| 105 */ |
| 106 flushStatusMessageQueuePeriodically_: function() { |
| 107 // Stop the periodic flusher if the queue becomes empty. |
| 108 if (this.statusMessageQueue_.length == 0) { |
| 109 this.statusMessageQueueFlushStarted_ = false; |
| 110 return; |
| 111 } |
| 112 this.statusMessageQueueFlushStarted_ = true; |
| 113 |
| 114 // Update the status message. |
| 115 var pair = this.statusMessageQueue_.shift(); |
| 116 var message = pair[0]; |
| 117 var delayMs = pair[1]; |
| 118 $('updateStatus').textContent = message; |
| 119 |
| 120 // Schedule the next flush with delay as needed. |
| 121 var self = this; |
| 122 window.setTimeout( |
| 123 function() { self.flushStatusMessageQueuePeriodically_() }, |
| 124 delayMs); |
| 125 }, |
| 126 |
| 127 updateEnable_: function(enable) { |
| 128 $('checkNow').disabled = !enable; |
| 129 }, |
| 130 |
| 131 setReleaseChannel_: function(channel) { |
| 132 // Write the value into the pref which will end up in the policy. |
| 133 // Eventually, the update engine will use the policy value as the |
| 134 // source truth for the update channel (see http://crosbug/17015). |
| 135 Preferences.setStringPref("cros.system.releaseChannel", channel); |
| 136 this.selectedChannel_ = channel; |
| 137 chrome.send('SetReleaseTrack', [channel]); |
| 138 }, |
| 139 |
| 140 selectedOptionOnChange_: function(value) { |
| 141 if (value == 'dev-channel') { |
| 142 // Open confirm dialog. |
| 143 var self = this; |
| 144 AlertOverlay.show( |
| 145 localStrings.getString('channel_warning_header'), |
| 146 localStrings.getString('channel_warning_text'), |
| 147 localStrings.getString('ok'), |
| 148 localStrings.getString('cancel'), |
| 149 function() { |
| 150 // Ok, so set release track and update selected channel. |
| 151 $('channelWarningBlock').hidden = false; |
| 152 self.setReleaseChannel_(value); }, |
| 153 function() { |
| 154 // Cancel, so switch back to previous selected channel. |
| 155 self.updateSelectedOption_(self.selectedChannel_); } |
| 156 ); |
| 157 } else { |
| 158 $('channelWarningBlock').hidden = true; |
| 159 this.setReleaseChannel_(value); |
| 160 } |
| 161 }, |
| 162 |
| 163 // Updates the selected option in 'channelSelect' <select> element. |
| 164 updateSelectedOption_: function(value) { |
| 165 var options = $('channelSelect').querySelectorAll('option'); |
| 166 for (var i = 0; i < options.length; i++) { |
| 167 var option = options[i]; |
| 168 if (option.value == value) { |
| 169 option.selected = true; |
| 170 this.selectedChannel_ = value; |
| 171 } |
| 172 } |
| 173 if (value == 'dev-channel') |
| 174 $('channelWarningBlock').hidden = false; |
| 175 }, |
| 176 |
| 177 // Changes the "check now" button to "restart now" button. |
| 178 changeToRestartButton_: function() { |
| 179 $('checkNow').textContent = localStrings.getString('restart_now'); |
| 180 $('checkNow').disabled = false; |
| 181 $('checkNow').onclick = function(event) { |
| 182 chrome.send('RestartNow'); |
| 183 }; |
| 184 }, |
| 185 }; |
| 186 |
| 187 AboutPage.updateOSVersionCallback = function(versionString) { |
| 188 AboutPage.getInstance().updateOSVersion_(versionString); |
| 189 }; |
| 190 |
| 191 AboutPage.updateOSFirmwareCallback = function(firmwareString) { |
| 192 AboutPage.getInstance().updateOSFirmware_(firmwareString); |
| 193 }; |
| 194 |
| 195 AboutPage.updateStatusCallback = function(message, insertDelay) { |
| 196 AboutPage.getInstance().updateStatus_(message, insertDelay); |
| 197 }; |
| 198 |
| 199 AboutPage.updateEnableCallback = function(enable) { |
| 200 AboutPage.getInstance().updateEnable_(enable); |
| 201 }; |
| 202 |
| 203 AboutPage.updateSelectedOptionCallback = function(value) { |
| 204 AboutPage.getInstance().updateSelectedOption_(value); |
| 205 }; |
| 206 |
| 207 AboutPage.setUpdateImage = function(state) { |
| 208 $('updateIcon').className= 'update-icon ' + state; |
| 209 }; |
| 210 |
| 211 AboutPage.changeToRestartButton = function() { |
| 212 AboutPage.getInstance().changeToRestartButton_(); |
| 213 }; |
| 214 |
| 215 // Export |
| 216 return { |
| 217 AboutPage: AboutPage |
| 218 }; |
| 219 |
| 220 }); |
OLD | NEW |