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

Side by Side Diff: chrome/browser/resources/about_page/about_page.js

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

Powered by Google App Engine
This is Rietveld 408576698