• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5cr.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').classList.add('hidden');
58        $('aboutPageMoreInfo').classList.remove('hidden');
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    selectedOptionOnChange_: function(value) {
132      if (value == 'dev-channel') {
133        // Open confirm dialog.
134        var self = this;
135        AlertOverlay.show(
136          localStrings.getString('channel_warning_header'),
137          localStrings.getString('channel_warning_text'),
138          localStrings.getString('ok'),
139          localStrings.getString('cancel'),
140          function() {
141            // Ok, so set release track and update selected channel.
142            $('channelWarningBlock').hidden = false;
143            chrome.send('SetReleaseTrack', [value]);
144            self.selectedChannel_ = value; },
145          function() {
146            // Cancel, so switch back to previous selected channel.
147            self.updateSelectedOption_(self.selectedChannel_); }
148          );
149      } else {
150        $('channelWarningBlock').hidden = true;
151        chrome.send('SetReleaseTrack', [value]);
152        this.selectedChannel_ = value;
153      }
154    },
155
156    // Updates the selected option in 'channelSelect' <select> element.
157    updateSelectedOption_: function(value) {
158      var options = $('channelSelect').querySelectorAll('option');
159      for (var i = 0; i < options.length; i++) {
160        var option = options[i];
161        if (option.value == value) {
162          option.selected = true;
163          this.selectedChannel_ = value;
164        }
165      }
166      if (value == 'dev-channel')
167        $('channelWarningBlock').hidden = false;
168    },
169
170    // Changes the "check now" button to "restart now" button.
171    changeToRestartButton_: function() {
172      $('checkNow').textContent = localStrings.getString('restart_now');
173      $('checkNow').disabled = false;
174      $('checkNow').onclick = function(event) {
175        chrome.send('RestartNow');
176      };
177    },
178  };
179
180  AboutPage.updateOSVersionCallback = function(versionString) {
181    AboutPage.getInstance().updateOSVersion_(versionString);
182  };
183
184  AboutPage.updateOSFirmwareCallback = function(firmwareString) {
185    AboutPage.getInstance().updateOSFirmware_(firmwareString);
186  };
187
188  AboutPage.updateStatusCallback = function(message, insertDelay) {
189    AboutPage.getInstance().updateStatus_(message, insertDelay);
190  };
191
192  AboutPage.updateEnableCallback = function(enable) {
193    AboutPage.getInstance().updateEnable_(enable);
194  };
195
196  AboutPage.updateSelectedOptionCallback = function(value) {
197    AboutPage.getInstance().updateSelectedOption_(value);
198  };
199
200  AboutPage.setUpdateImage = function(state) {
201    $('updateIcon').className= 'update-icon ' + state;
202  };
203
204  AboutPage.changeToRestartButton = function() {
205    AboutPage.getInstance().changeToRestartButton_();
206  };
207
208  // Export
209  return {
210    AboutPage: AboutPage
211  };
212
213});
214