OLD | NEW |
| (Empty) |
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. | |
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 var self = this; | |
62 $('channelSelect').onchange = function(event) { | |
63 self.channelSelectOnChanged_(event.target.value); | |
64 } | |
65 | |
66 // Notify the handler that the page is ready. | |
67 chrome.send('PageReady'); | |
68 }, | |
69 | |
70 // Update the Default Browsers section based on the current state. | |
71 updateOSVersion_: function(versionString) { | |
72 $('osVersion0').textContent = versionString; | |
73 $('osVersion1').textContent = versionString; | |
74 }, | |
75 | |
76 updateOSFirmware_: function(firmwareString) { | |
77 $('osFirmware0').textContent = firmwareString; | |
78 $('osFirmware1').textContent = firmwareString; | |
79 }, | |
80 | |
81 /** | |
82 * Updates the status message like "Checking for update...". | |
83 * @param {string} message The message to be shown. | |
84 * @param {boolean} insertDelay show the message for a while. | |
85 * @private | |
86 */ | |
87 updateStatus_: function(message, insertDelay) { | |
88 // Add the message to the queue with delay if needed. | |
89 // The delay is inserted so users can read the message. | |
90 var delayMs = insertDelay ? MESSAGE_DELAY_MS : 0; | |
91 this.statusMessageQueue_.push([message, delayMs]); | |
92 // Start the periodic flusher if not started. | |
93 if (this.statusMessageQueueFlushStarted_ == false) { | |
94 this.flushStatusMessageQueuePeriodically_(); | |
95 } | |
96 }, | |
97 | |
98 /** | |
99 * Flushes the status message queue periodically using a timer. | |
100 * @private | |
101 */ | |
102 flushStatusMessageQueuePeriodically_: function() { | |
103 // Stop the periodic flusher if the queue becomes empty. | |
104 if (this.statusMessageQueue_.length == 0) { | |
105 this.statusMessageQueueFlushStarted_ = false; | |
106 return; | |
107 } | |
108 this.statusMessageQueueFlushStarted_ = true; | |
109 | |
110 // Update the status message. | |
111 var pair = this.statusMessageQueue_.shift(); | |
112 var message = pair[0]; | |
113 var delayMs = pair[1]; | |
114 $('updateStatus').textContent = message; | |
115 | |
116 // Schedule the next flush with delay as needed. | |
117 var self = this; | |
118 window.setTimeout( | |
119 function() { self.flushStatusMessageQueuePeriodically_() }, | |
120 delayMs); | |
121 }, | |
122 | |
123 updateEnable_: function(enable) { | |
124 $('checkNow').disabled = !enable; | |
125 }, | |
126 | |
127 enableReleaseChannel_: function(enable) { | |
128 $('channelSelect').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 // This function is called when the user changes the release channel from | |
141 // the 'channelSelect' <select> element. It either calls back into Chrome to | |
142 // switch the channel or displays a confirmation box if switching to dev. | |
143 channelSelectOnChanged_: function(value) { | |
144 if (value == 'dev-channel') { | |
145 // Open confirm dialog. | |
146 var self = this; | |
147 AlertOverlay.show( | |
148 localStrings.getString('channel_warning_header'), | |
149 localStrings.getString('channel_warning_text'), | |
150 localStrings.getString('ok'), | |
151 localStrings.getString('cancel'), | |
152 function() { | |
153 // Ok, so set release track and update selected channel. | |
154 $('channelWarningBlock').hidden = false; | |
155 self.setReleaseChannel_(value); }, | |
156 function() { | |
157 // Cancel, so switch back to previous selected channel. | |
158 self.updateSelectedOption_(self.selectedChannel_); } | |
159 ); | |
160 } else { | |
161 $('channelWarningBlock').hidden = true; | |
162 this.setReleaseChannel_(value); | |
163 } | |
164 }, | |
165 | |
166 // Updates the selected option in 'channelSelect' <select> element. | |
167 updateSelectedOption_: function(value) { | |
168 var options = $('channelSelect').querySelectorAll('option'); | |
169 for (var i = 0; i < options.length; i++) { | |
170 var option = options[i]; | |
171 if (option.value == value) { | |
172 option.selected = true; | |
173 this.selectedChannel_ = value; | |
174 } | |
175 } | |
176 if (value == 'dev-channel') | |
177 $('channelWarningBlock').hidden = false; | |
178 }, | |
179 | |
180 // Changes the "check now" button to "restart now" button. | |
181 changeToRestartButton_: function() { | |
182 $('checkNow').textContent = localStrings.getString('restart_now'); | |
183 $('checkNow').disabled = false; | |
184 $('checkNow').onclick = function(event) { | |
185 chrome.send('RestartNow'); | |
186 }; | |
187 }, | |
188 }; | |
189 | |
190 AboutPage.updateOSVersionCallback = function(versionString) { | |
191 AboutPage.getInstance().updateOSVersion_(versionString); | |
192 }; | |
193 | |
194 AboutPage.updateOSFirmwareCallback = function(firmwareString) { | |
195 AboutPage.getInstance().updateOSFirmware_(firmwareString); | |
196 }; | |
197 | |
198 AboutPage.updateStatusCallback = function(message, insertDelay) { | |
199 AboutPage.getInstance().updateStatus_(message, insertDelay); | |
200 }; | |
201 | |
202 AboutPage.updateEnableCallback = function(enable) { | |
203 AboutPage.getInstance().updateEnable_(enable); | |
204 }; | |
205 | |
206 AboutPage.updateEnableReleaseChannelCallback = function(enable) { | |
207 AboutPage.getInstance().enableReleaseChannel_(enable); | |
208 }; | |
209 | |
210 AboutPage.updateSelectedOptionCallback = function(value) { | |
211 AboutPage.getInstance().updateSelectedOption_(value); | |
212 }; | |
213 | |
214 AboutPage.setUpdateImage = function(state) { | |
215 $('updateIcon').className= 'update-icon ' + state; | |
216 }; | |
217 | |
218 AboutPage.changeToRestartButton = function() { | |
219 AboutPage.getInstance().changeToRestartButton_(); | |
220 }; | |
221 | |
222 // Export | |
223 return { | |
224 AboutPage: AboutPage | |
225 }; | |
226 | |
227 }); | |
OLD | NEW |