summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/about_page.js
blob: 8fc57a03f03abfe26a8f32cc5c729384d5223ed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

cr.define('options', function() {
  const OptionsPage = options.OptionsPage;

  /**
   * The number of milliseconds used for showing a message.
   * @type {number}
   */
  const MESSAGE_DELAY_MS = 1000;  // 1 sec.

  /**
   * Encapsulated handling of about page.
   */
  function AboutPage() {
    OptionsPage.call(this, 'about', templateData.aboutPage, 'aboutPage');
  }

  cr.addSingletonGetter(AboutPage);

  AboutPage.prototype = {
    // Inherit AboutPage from OptionsPage.
    __proto__: OptionsPage.prototype,

    /**
     * The queue is used for updating the status message with delay, like:
     * [["Check for update...", 1000], ["Chrome OS is up to date", 0]]
     * @type {!Array.<!Array>}
     */
    statusMessageQueue_: [],

    /**
     * True if the status message queue flush started.
     * @type {boolean}
     */
    statusMessageQueueFlushStarted_: false,

    // Initialize AboutPage.
    initializePage: function() {
      // Call base class implementation to start preference initialization.
      OptionsPage.prototype.initializePage.call(this);

      $('checkNow').onclick = function(event) {
        chrome.send('CheckNow');
      };

      $('moreInfoButton').onclick = function(event) {
        $('aboutPageLessInfo').classList.add('hidden');
        $('aboutPageMoreInfo').classList.remove('hidden');
      };

      if (cr.commandLine.options['--bwsi']) {
        $('channelSelect').disabled = true;
      } else {
        $('channelSelect').onchange = function(event) {
          var channel = event.target.value;
          chrome.send('SetReleaseTrack', [channel]);
        };
      }

      // Notify the handler that the page is ready.
      chrome.send('PageReady');
    },

    // Update the Default Browsers section based on the current state.
    updateOSVersion_: function(versionString) {
      $('osVersion0').textContent = versionString;
      $('osVersion1').textContent = versionString;
    },

    /**
     * Updates the status message like "Checking for update...".
     * @param {string} message The message to be shown.
     * @param {boolean} insertDelay show the message for a while.
     * @private
     */
    updateStatus_: function(message, insertDelay) {
      // Add the message to the queue with delay if needed.
      // The delay is inserted so users can read the message.
      var delayMs = insertDelay ? MESSAGE_DELAY_MS : 0;
      this.statusMessageQueue_.push([message, delayMs]);
      // Start the periodic flusher if not started.
      if (this.statusMessageQueueFlushStarted_ == false) {
        this.flushStatusMessageQueuePeriodically_();
      }
    },

    /**
     * Flushes the status message queue periodically using a timer.
     * @private
     */
    flushStatusMessageQueuePeriodically_: function() {
      // Stop the periodic flusher if the queue becomes empty.
      if (this.statusMessageQueue_.length == 0) {
        this.statusMessageQueueFlushStarted_ = false;
        return;
      }
      this.statusMessageQueueFlushStarted_ = true;

      // Update the status message.
      var pair = this.statusMessageQueue_.shift();
      var message = pair[0];
      var delayMs = pair[1];
      $('updateStatus').textContent = message;

      // Schedule the next flush with delay as needed.
      var self = this;
      window.setTimeout(
          function() { self.flushStatusMessageQueuePeriodically_() },
          delayMs);
    },

    updateEnable_: function(enable) {
      $('checkNow').disabled = !enable;
    },

    // Updates the selected option in 'channelSelect' <select> element.
    updateSelectedOption_: function(value) {
      var options = $('channelSelect').querySelectorAll('option');
      for (var i = 0; i < options.length; i++) {
        var option = options[i];
        if (option.value == value) {
          option.selected = true;
        }
      }
    },

    // Changes the "check now" button to "restart now" button.
    changeToRestartButton_: function() {
      $('checkNow').textContent = localStrings.getString('restart_now');
      $('checkNow').disabled = false;
      $('checkNow').onclick = function(event) {
        chrome.send('RestartNow');
      };
    },
  };

  AboutPage.updateOSVersionCallback = function(versionString) {
    AboutPage.getInstance().updateOSVersion_(versionString);
  };

  AboutPage.updateStatusCallback = function(message, insertDelay) {
    AboutPage.getInstance().updateStatus_(message, insertDelay);
  };

  AboutPage.updateEnableCallback = function(enable) {
    AboutPage.getInstance().updateEnable_(enable);
  };

  AboutPage.updateSelectedOptionCallback = function(value) {
    AboutPage.getInstance().updateSelectedOption_(value);
  };

  AboutPage.setUpdateImage = function(state) {
    $('updateIcon').className= 'update-icon ' + state;
  };

  AboutPage.changeToRestartButton = function() {
    AboutPage.getInstance().changeToRestartButton_();
  };

  // Export
  return {
    AboutPage: AboutPage
  };

});