summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options/startup_page_manager.js
blob: 67b804e7fde7b72455b83731598a3488dc8dfbca (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
// 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;
  const ArrayDataModel = cr.ui.ArrayDataModel;
  const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel;

  /**
   * Encapsulated handling of startup page management page.
   * @constructor
   */
  function StartupPageManager() {
    this.activeNavTab = null;
    OptionsPage.call(this, 'startupPages',
                     templateData.StartupPageManagerPage,
                     'startupPageManagerPage');
  }

  cr.addSingletonGetter(StartupPageManager);

  StartupPageManager.prototype = {
    __proto__: OptionsPage.prototype,
    list_: null,

    initializePage: function() {
      OptionsPage.prototype.initializePage.call(this);

      var list = $('startupPagesFullList');
      options.browser_options.StartupPageList.decorate(list);
      list.autoExpands = true;
      list.selectionModel = new ListSingleSelectionModel;

      // Wire up controls.
      $('startupAddButton').onclick = function(event) {
        OptionsPage.showOverlay('addStartupPageOverlay');
      };

      // Remove Windows-style accelerators from button labels.
      // TODO(stuartmorgan): Remove this once the strings are updated.
      $('startupAddButton').textContent =
          localStrings.getStringWithoutAccelerator('startupAddButton');
    },

    /**
     * Updates the startup pages list with the given entries.
     * @param {Array} pages List of startup pages.
     * @private
     */
    updateStartupPages_: function(pages) {
      $('startupPagesFullList').dataModel = new ArrayDataModel(pages);
    },

    /**
     * Adds the given startup page at the current selection point.
     * @private
     */
    addStartupPage_: function(url) {
      var firstSelection =
          $('startupPagesFullList').selectionModel.selectedIndex;
      chrome.send('addStartupPage', [url, String(firstSelection)]);
    },
  };

  StartupPageManager.updateStartupPages = function(pages) {
    StartupPageManager.getInstance().updateStartupPages_(pages);
  };

  StartupPageManager.addStartupPage = function(url) {
    StartupPageManager.getInstance().addStartupPage_(url);
  };

  // Export
  return {
    StartupPageManager: StartupPageManager
  };

});