OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 const OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
7 const ArrayDataModel = cr.ui.ArrayDataModel; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
9 | 9 |
10 // | 10 // |
(...skipping 26 matching lines...) Expand all Loading... |
37 * Initialize BrowserOptions page. | 37 * Initialize BrowserOptions page. |
38 */ | 38 */ |
39 initializePage: function() { | 39 initializePage: function() { |
40 // Call base class implementation to start preference initialization. | 40 // Call base class implementation to start preference initialization. |
41 OptionsPage.prototype.initializePage.call(this); | 41 OptionsPage.prototype.initializePage.call(this); |
42 | 42 |
43 // Wire up controls. | 43 // Wire up controls. |
44 $('startupUseCurrentButton').onclick = function(event) { | 44 $('startupUseCurrentButton').onclick = function(event) { |
45 chrome.send('setStartupPagesToCurrentPages'); | 45 chrome.send('setStartupPagesToCurrentPages'); |
46 }; | 46 }; |
47 $('startupPageManagerButton').onclick = function(event) { | 47 $('startupAddButton').onclick = function(event) { |
48 OptionsPage.showPageByName('startupPages'); | 48 OptionsPage.showOverlay('addStartupPageOverlay'); |
49 }; | 49 }; |
50 $('defaultSearchManageEnginesButton').onclick = function(event) { | 50 $('defaultSearchManageEnginesButton').onclick = function(event) { |
51 OptionsPage.showPageByName('searchEngines'); | 51 OptionsPage.showPageByName('searchEngines'); |
52 chrome.send('coreOptionsUserMetricsAction', | 52 chrome.send('coreOptionsUserMetricsAction', |
53 ['Options_ManageSearchEngines']); | 53 ['Options_ManageSearchEngines']); |
54 }; | 54 }; |
55 $('instantEnableCheckbox').onclick = function(event) { | 55 $('instantEnableCheckbox').onclick = function(event) { |
56 var alreadyConfirmed = $('instantDialogShown').checked; | 56 var alreadyConfirmed = $('instantDialogShown').checked; |
57 | 57 |
58 if (this.checked && !alreadyConfirmed) { | 58 if (this.checked && !alreadyConfirmed) { |
59 // Leave disabled for now. The PrefCheckbox handler already set it to | 59 // Leave disabled for now. The PrefCheckbox handler already set it to |
60 // true so undo that. | 60 // true so undo that. |
61 Preferences.setBooleanPref(this.pref, false, this.metric); | 61 Preferences.setBooleanPref(this.pref, false, this.metric); |
62 OptionsPage.showOverlay('instantConfirmOverlay'); | 62 OptionsPage.showOverlay('instantConfirmOverlay'); |
63 } | 63 } |
64 }; | 64 }; |
65 $('defaultSearchEngine').onchange = this.setDefaultSearchEngine; | 65 $('defaultSearchEngine').onchange = this.setDefaultSearchEngine; |
66 | 66 |
67 var homepageField = $('homepageURL'); | 67 var homepageField = $('homepageURL'); |
68 $('homepageUseNTPButton').onchange = | 68 $('homepageUseNTPButton').onchange = |
69 this.handleHomepageUseNTPButtonChange_.bind(this); | 69 this.handleHomepageUseNTPButtonChange_.bind(this); |
70 $('homepageUseURLButton').onchange = | 70 $('homepageUseURLButton').onchange = |
71 this.handleHomepageUseURLButtonChange_.bind(this); | 71 this.handleHomepageUseURLButtonChange_.bind(this); |
72 homepageField.onchange = this.handleHomepageURLChange_.bind(this); | 72 homepageField.onchange = this.handleHomepageURLChange_.bind(this); |
73 homepageField.oninput = this.handleHomepageURLChange_.bind(this); | 73 homepageField.oninput = this.handleHomepageURLChange_.bind(this); |
74 | 74 |
75 // Ensure that changes are committed when closing the page. | 75 // Ensure that changes are committed when closing the page. |
76 window.addEventListener('unload', function() { | 76 window.addEventListener('unload', function() { |
77 if (document.activeElement == homepageField) | 77 if (document.activeElement == homepageField) |
78 homepageField.blur(); | 78 homepageField.blur(); |
79 }); | 79 }); |
| 80 |
| 81 // Remove Windows-style accelerators from button labels. |
| 82 // TODO(stuartmorgan): Remove this once the strings are updated. |
| 83 $('startupAddButton').textContent = |
| 84 localStrings.getStringWithoutAccelerator('startupAddButton'); |
80 | 85 |
81 if (!cr.isChromeOS) { | 86 if (!cr.isChromeOS) { |
82 $('defaultBrowserUseAsDefaultButton').onclick = function(event) { | 87 $('defaultBrowserUseAsDefaultButton').onclick = function(event) { |
83 chrome.send('becomeDefaultBrowser'); | 88 chrome.send('becomeDefaultBrowser'); |
84 }; | 89 }; |
85 } | 90 } |
86 | 91 |
87 var list = $('startupPagesShortList'); | 92 var list = $('startupPagesList'); |
88 options.browser_options.StartupPageList.decorate(list); | 93 options.browser_options.StartupPageList.decorate(list); |
89 list.autoExpands = true; | 94 list.autoExpands = true; |
90 list.selectionModel = new ListSingleSelectionModel; | 95 list.selectionModel = new ListSingleSelectionModel; |
91 | 96 |
92 // Check if we are in the guest mode. | 97 // Check if we are in the guest mode. |
93 if (cr.commandLine.options['--bwsi']) { | 98 if (cr.commandLine.options['--bwsi']) { |
94 // Hide the startup section. | 99 // Hide the startup section. |
95 $('startupSection').classList.add('hidden'); | 100 $('startupSection').classList.add('hidden'); |
96 } else { | 101 } else { |
97 // Initialize control enabled states. | 102 // Initialize control enabled states. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 shouldEnableCustomStartupPageControls_: function(pages) { | 167 shouldEnableCustomStartupPageControls_: function(pages) { |
163 return $('startupShowPagesButton').checked; | 168 return $('startupShowPagesButton').checked; |
164 }, | 169 }, |
165 | 170 |
166 /** | 171 /** |
167 * Updates the startup pages list with the given entries. | 172 * Updates the startup pages list with the given entries. |
168 * @private | 173 * @private |
169 * @param {Array} pages List of startup pages. | 174 * @param {Array} pages List of startup pages. |
170 */ | 175 */ |
171 updateStartupPages_: function(pages) { | 176 updateStartupPages_: function(pages) { |
172 var list = $('startupPagesShortList'); | 177 $('startupPagesList').dataModel = new ArrayDataModel(pages); |
173 list.dataModel = new ArrayDataModel(pages); | |
174 if (pages.length > 0 && pages.length <= 10) { | |
175 list.classList.remove("hidden"); | |
176 $('startupPageManagement').classList.add('settings-list'); | |
177 $('startupShowPagesLabel').textContent = | |
178 localStrings.getStringWithoutAccelerator('startupShowPages'); | |
179 } else { | |
180 list.classList.add("hidden"); | |
181 $('startupPageManagement').classList.remove('settings-list'); | |
182 $('startupShowPagesLabel').textContent = | |
183 localStrings.getStringWithoutAccelerator('startupShowManyPages'); | |
184 } | |
185 }, | 178 }, |
186 | 179 |
187 /** | 180 /** |
188 * Handles change events of the radio button 'homepageUseURLButton'. | 181 * Handles change events of the radio button 'homepageUseURLButton'. |
189 * @private | 182 * @private |
190 * @param {event} change event. | 183 * @param {event} change event. |
191 */ | 184 */ |
192 handleHomepageUseURLButtonChange_: function(event) { | 185 handleHomepageUseURLButtonChange_: function(event) { |
193 Preferences.setBooleanPref('homepage_is_newtabpage', false); | 186 Preferences.setBooleanPref('homepage_is_newtabpage', false); |
194 }, | 187 }, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 !this.homepage_is_newtabpage_pref_.managed)); | 330 !this.homepage_is_newtabpage_pref_.managed)); |
338 }, | 331 }, |
339 | 332 |
340 /** | 333 /** |
341 * Sets the enabled state of the custom startup page list controls | 334 * Sets the enabled state of the custom startup page list controls |
342 * based on the current startup radio button selection. | 335 * based on the current startup radio button selection. |
343 * @private | 336 * @private |
344 */ | 337 */ |
345 updateCustomStartupPageControlStates_: function() { | 338 updateCustomStartupPageControlStates_: function() { |
346 var disable = !this.shouldEnableCustomStartupPageControls_(); | 339 var disable = !this.shouldEnableCustomStartupPageControls_(); |
347 $('startupPagesShortList').disabled = disable; | 340 $('startupPagesList').disabled = disable; |
348 $('startupUseCurrentButton').disabled = disable; | 341 $('startupUseCurrentButton').disabled = disable; |
349 $('startupPageManagerButton').disabled = disable; | 342 $('startupAddButton').disabled = disable; |
350 }, | 343 }, |
351 | 344 |
352 /** | 345 /** |
353 * Set the default search engine based on the popup selection. | 346 * Set the default search engine based on the popup selection. |
354 */ | 347 */ |
355 setDefaultSearchEngine: function() { | 348 setDefaultSearchEngine: function() { |
356 var engineSelect = $('defaultSearchEngine'); | 349 var engineSelect = $('defaultSearchEngine'); |
357 var selectedIndex = engineSelect.selectedIndex; | 350 var selectedIndex = engineSelect.selectedIndex; |
358 if (selectedIndex >= 0) { | 351 if (selectedIndex >= 0) { |
359 var selection = engineSelect.options[selectedIndex]; | 352 var selection = engineSelect.options[selectedIndex]; |
360 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | 353 chrome.send('setDefaultSearchEngine', [String(selection.value)]); |
361 } | 354 } |
362 }, | 355 }, |
| 356 |
| 357 /** |
| 358 * Adds the given startup page at the current selection point. |
| 359 * @private |
| 360 */ |
| 361 addStartupPage_: function(url) { |
| 362 var selectedIndex = |
| 363 $('startupPagesList').selectionModel.selectedIndex; |
| 364 chrome.send('addStartupPage', [url, String(selectedIndex)]); |
| 365 }, |
363 }; | 366 }; |
364 | 367 |
365 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, | 368 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, |
366 canBeDefault) { | 369 canBeDefault) { |
367 if (!cr.isChromeOS) { | 370 if (!cr.isChromeOS) { |
368 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, | 371 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, |
369 isDefault, | 372 isDefault, |
370 canBeDefault); | 373 canBeDefault); |
371 } | 374 } |
372 }; | 375 }; |
373 | 376 |
374 BrowserOptions.updateSearchEngines = function(engines, defaultValue) { | 377 BrowserOptions.updateSearchEngines = function(engines, defaultValue) { |
375 BrowserOptions.getInstance().updateSearchEngines_(engines, defaultValue); | 378 BrowserOptions.getInstance().updateSearchEngines_(engines, defaultValue); |
376 }; | 379 }; |
377 | 380 |
378 BrowserOptions.updateStartupPages = function(pages) { | 381 BrowserOptions.updateStartupPages = function(pages) { |
379 BrowserOptions.getInstance().updateStartupPages_(pages); | 382 BrowserOptions.getInstance().updateStartupPages_(pages); |
380 StartupPageManager.getInstance().updateStartupPages_(pages); | 383 }; |
| 384 |
| 385 BrowserOptions.addStartupPage = function(url) { |
| 386 BrowserOptions.getInstance().addStartupPage_(url); |
381 }; | 387 }; |
382 | 388 |
383 // Export | 389 // Export |
384 return { | 390 return { |
385 BrowserOptions: BrowserOptions | 391 BrowserOptions: BrowserOptions |
386 }; | 392 }; |
387 | 393 |
388 }); | 394 }); |
OLD | NEW |