OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // | 5 // |
6 // BrowserOptions class | 6 // BrowserOptions class |
7 // Encapsulated handling of browser options page. | 7 // Encapsulated handling of browser options page. |
8 // | 8 // |
9 function BrowserOptions() { | 9 function BrowserOptions() { |
10 OptionsPage.call(this, 'browser', templateData.browserPage, 'browserPage'); | 10 OptionsPage.call(this, 'browser', templateData.browserPage, 'browserPage'); |
11 } | 11 } |
12 | 12 |
13 cr.addSingletonGetter(BrowserOptions); | 13 cr.addSingletonGetter(BrowserOptions); |
14 | 14 |
15 BrowserOptions.prototype = { | 15 BrowserOptions.prototype = { |
16 // Inherit BrowserOptions from OptionsPage. | 16 // Inherit BrowserOptions from OptionsPage. |
17 __proto__: OptionsPage.prototype, | 17 __proto__: OptionsPage.prototype, |
18 | 18 |
19 /** | 19 /** |
20 * Initialize BrowserOptions page. | 20 * Initialize BrowserOptions page. |
21 */ | 21 */ |
22 initializePage: function() { | 22 initializePage: function() { |
23 // Call base class implementation to start preference initialization. | 23 // Call base class implementation to start preference initialization. |
24 OptionsPage.prototype.initializePage.call(this); | 24 OptionsPage.prototype.initializePage.call(this); |
25 | 25 |
26 // Wire up buttons. | 26 // Wire up controls. |
| 27 var self = this; |
| 28 $('startupPages').onchange = function(event) { |
| 29 self.updateRemoveButtonState_(); |
| 30 }; |
27 $('startupAddButton').onclick = function(event) { | 31 $('startupAddButton').onclick = function(event) { |
28 OptionsPage.showOverlay('addStartupPageOverlay'); | 32 OptionsPage.showOverlay('addStartupPageOverlay'); |
29 }; | 33 }; |
30 $('startupRemoveButton').onclick = function(event) { | 34 $('startupRemoveButton').onclick = function(event) { |
31 // TODO(stuartmorgan): Remove selected element(s). | 35 self.removeSelectedStartupPages_(); |
32 }; | 36 }; |
33 $('startupUseCurrentButton').onclick = function(event) { | 37 $('startupUseCurrentButton').onclick = function(event) { |
34 // TODO(stuartmorgan): Add all open tabs (except this one). | 38 chrome.send('setStartupPagesToCurrentPages'); |
35 }; | 39 }; |
36 $('defaultSearchManageEnginesButton').onclick = function(event) { | 40 $('defaultSearchManageEnginesButton').onclick = function(event) { |
37 // TODO(stuartmorgan): Spawn search engine management sub-dialog. | 41 // TODO(stuartmorgan): Spawn search engine management sub-dialog. |
38 }; | 42 }; |
39 $('defaultBrowserUseAsDefaultButton').onclick = function(event) { | 43 $('defaultBrowserUseAsDefaultButton').onclick = function(event) { |
40 chrome.send('becomeDefaultBrowser'); | 44 chrome.send('becomeDefaultBrowser'); |
41 }; | 45 }; |
42 | 46 |
43 // Remove Windows-style accelerators from button labels. | 47 // Remove Windows-style accelerators from button labels. |
44 // TODO(stuartmorgan): Remove this once the strings are updated. | 48 // TODO(stuartmorgan): Remove this once the strings are updated. |
(...skipping 29 matching lines...) Expand all Loading... |
74 }, | 78 }, |
75 | 79 |
76 /** | 80 /** |
77 * Updates the search engine popup with the given entries. | 81 * Updates the search engine popup with the given entries. |
78 * @param {Array} engines List of available search engines. | 82 * @param {Array} engines List of available search engines. |
79 * @param {Integer} defaultValue The value of the current default engine. | 83 * @param {Integer} defaultValue The value of the current default engine. |
80 */ | 84 */ |
81 updateSearchEngines_: function(engines, defaultValue) { | 85 updateSearchEngines_: function(engines, defaultValue) { |
82 this.clearSearchEngines_(); | 86 this.clearSearchEngines_(); |
83 engineSelect = $('defaultSearchEngine'); | 87 engineSelect = $('defaultSearchEngine'); |
84 engineCount = engines.length | 88 engineCount = engines.length; |
85 var defaultIndex = -1; | 89 var defaultIndex = -1; |
86 for (var i = 0; i < engineCount; i++) { | 90 for (var i = 0; i < engineCount; i++) { |
87 var engine = engines[i] | 91 var engine = engines[i]; |
88 var option = new Option(engine['name'], engine['index']); | 92 var option = new Option(engine['name'], engine['index']); |
89 if (defaultValue == option.value) | 93 if (defaultValue == option.value) |
90 defaultIndex = i; | 94 defaultIndex = i; |
91 engineSelect.appendChild(option); | 95 engineSelect.appendChild(option); |
92 } | 96 } |
93 if (defaultIndex >= 0) | 97 if (defaultIndex >= 0) |
94 engineSelect.selectedIndex = defaultIndex; | 98 engineSelect.selectedIndex = defaultIndex; |
95 }, | 99 }, |
96 | 100 |
97 /** | 101 /** |
| 102 * Clears the startup page list. |
| 103 * @private |
| 104 */ |
| 105 clearStartupPages_: function() { |
| 106 $('startupPages').textContent = ''; |
| 107 }, |
| 108 |
| 109 /** |
| 110 * Updates the startup pages list with the given entries. |
| 111 * @param {Array} pages List of startup pages. |
| 112 */ |
| 113 updateStartupPages_: function(pages) { |
| 114 // TODO(stuartmorgan): Replace <select> with a DOMUI List. |
| 115 this.clearStartupPages_(); |
| 116 pageList = $('startupPages'); |
| 117 pageCount = pages.length; |
| 118 for (var i = 0; i < pageCount; i++) { |
| 119 var page = pages[i]; |
| 120 var option = new Option(page['title']); |
| 121 option.title = page['tooltip']; |
| 122 pageList.appendChild(option); |
| 123 } |
| 124 |
| 125 this.updateRemoveButtonState_(); |
| 126 }, |
| 127 |
| 128 /** |
| 129 * Sets the enabled state of the startup page Remove button based on |
| 130 * the current selection in the startup pages list. |
| 131 */ |
| 132 updateRemoveButtonState_: function() { |
| 133 $('startupRemoveButton').disabled = ($('startupPages').selectedIndex == -1); |
| 134 }, |
| 135 |
| 136 /** |
| 137 * Removes the selected startup pages. |
| 138 */ |
| 139 removeSelectedStartupPages_: function() { |
| 140 var pageSelect = $('startupPages'); |
| 141 var optionCount = pageSelect.options.length; |
| 142 var selections = []; |
| 143 for (var i = 0; i < optionCount; i++) { |
| 144 if (pageSelect.options[i].selected) |
| 145 selections.push(String(i)); |
| 146 } |
| 147 chrome.send('removeStartupPages', selections); |
| 148 }, |
| 149 |
| 150 /** |
98 * Set the default search engine based on the popup selection. | 151 * Set the default search engine based on the popup selection. |
99 */ | 152 */ |
100 setDefaultBrowser: function() { | 153 setDefaultBrowser: function() { |
101 var engineSelect = $('defaultSearchEngine'); | 154 var engineSelect = $('defaultSearchEngine'); |
102 var selectedIndex = engineSelect.selectedIndex; | 155 var selectedIndex = engineSelect.selectedIndex; |
103 if (selectedIndex >= 0) { | 156 if (selectedIndex >= 0) { |
104 var selection = engineSelect.options[selectedIndex]; | 157 var selection = engineSelect.options[selectedIndex]; |
105 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | 158 chrome.send('setDefaultSearchEngine', [String(selection.value)]); |
106 } | 159 } |
107 }, | 160 }, |
108 }; | 161 }; |
109 | 162 |
110 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault) { | 163 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault) { |
111 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, | 164 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, |
112 isDefault); | 165 isDefault); |
113 } | 166 }; |
114 | 167 |
115 BrowserOptions.updateSearchEngines = function(engines, defaultValue) { | 168 BrowserOptions.updateSearchEngines = function(engines, defaultValue) { |
116 BrowserOptions.getInstance().updateSearchEngines_(engines, defaultValue); | 169 BrowserOptions.getInstance().updateSearchEngines_(engines, defaultValue); |
117 } | 170 }; |
| 171 |
| 172 BrowserOptions.updateStartupPages = function(pages) { |
| 173 BrowserOptions.getInstance().updateStartupPages_(pages); |
| 174 }; |
OLD | NEW |