OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 RepeatingButton = cr.ui.RepeatingButton; | 8 const RepeatingButton = cr.ui.RepeatingButton; |
9 | 9 |
10 // | 10 // |
11 // BrowserOptions class | 11 // BrowserOptions class |
12 // Encapsulated handling of browser options page. | 12 // Encapsulated handling of browser options page. |
13 // | 13 // |
14 function BrowserOptions() { | 14 function BrowserOptions() { |
15 OptionsPage.call(this, 'browser', | 15 OptionsPage.call(this, 'browser', |
16 templateData.browserPageTabTitle, | 16 templateData.browserPageTabTitle, |
17 'browserPage'); | 17 'browserPage'); |
18 } | 18 } |
19 | 19 |
20 cr.addSingletonGetter(BrowserOptions); | 20 cr.addSingletonGetter(BrowserOptions); |
21 | 21 |
22 BrowserOptions.prototype = { | 22 BrowserOptions.prototype = { |
23 // Inherit BrowserOptions from OptionsPage. | 23 // Inherit BrowserOptions from OptionsPage. |
24 __proto__: options.OptionsPage.prototype, | 24 __proto__: options.OptionsPage.prototype, |
25 | 25 |
26 // State variables. | 26 // State variables. |
27 syncEnabled: false, | 27 syncEnabled: false, |
28 syncSetupCompleted: false, | 28 syncSetupCompleted: false, |
29 | 29 |
| 30 showHomeButton_: false, |
| 31 homePageIsNtp_: false, |
| 32 |
30 /** | 33 /** |
31 * An autocomplete list that can be attached to the homepage URL text field | 34 * An autocomplete list that can be attached to the home page URL text field |
32 * during editing. | 35 * during editing. |
33 * @type {HTMLElement} | 36 * @type {HTMLElement} |
34 * @private | 37 * @private |
35 */ | 38 */ |
36 autocompleteList_: null, | 39 autocompleteList_: null, |
37 | 40 |
38 // The cached value of the instant.confirm_dialog_shown preference. | 41 // The cached value of the instant.confirm_dialog_shown preference. |
39 instantConfirmDialogShown_: false, | 42 instantConfirmDialogShown_: false, |
40 | 43 |
41 /** | 44 /** |
(...skipping 27 matching lines...) Expand all Loading... |
69 ['Options_InternetOptions']); | 72 ['Options_InternetOptions']); |
70 }); | 73 }); |
71 } | 74 } |
72 | 75 |
73 // On Startup section. | 76 // On Startup section. |
74 $('startupSetPages').addEventListener('click', function() { | 77 $('startupSetPages').addEventListener('click', function() { |
75 OptionsPage.navigateToPage('startup'); | 78 OptionsPage.navigateToPage('startup'); |
76 }); | 79 }); |
77 | 80 |
78 // Appearance section. | 81 // Appearance section. |
79 $('change-home-page').addEventListener('click', function(event) { | 82 $('home-page-select').addEventListener( |
80 OptionsPage.navigateToPage('homePageOverlay'); | 83 'change', this.onHomePageSelectChange_.bind(this)); |
| 84 |
| 85 ['browser.show_home_button', |
| 86 'homepage', |
| 87 'homepage_is_newtabpage'].forEach(function(pref) { |
| 88 Preferences.getInstance().addEventListener( |
| 89 pref, |
| 90 self.onHomePagePrefChanged_.bind(self)); |
81 }); | 91 }); |
| 92 |
82 $('themes-gallery').addEventListener('click', function(event) { | 93 $('themes-gallery').addEventListener('click', function(event) { |
83 window.open(localStrings.getString('themesGalleryURL')); | 94 window.open(localStrings.getString('themesGalleryURL')); |
84 }); | 95 }); |
85 $('themes-reset').addEventListener('click', function(event) { | 96 $('themes-reset').addEventListener('click', function(event) { |
86 chrome.send('themesReset'); | 97 chrome.send('themesReset'); |
87 }); | 98 }); |
88 | 99 |
89 // Device section (ChromeOS only). | 100 // Device section (ChromeOS only). |
90 if (cr.isChromeOS) { | 101 if (cr.isChromeOS) { |
91 $('keyboard-settings-button').addEventListener('click', function(evt) { | 102 $('keyboard-settings-button').addEventListener('click', function(evt) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 /** | 318 /** |
308 * Get the start/stop sync button DOM element. | 319 * Get the start/stop sync button DOM element. |
309 * @return {DOMElement} The start/stop sync button. | 320 * @return {DOMElement} The start/stop sync button. |
310 * @private | 321 * @private |
311 */ | 322 */ |
312 getStartStopSyncButton_: function() { | 323 getStartStopSyncButton_: function() { |
313 return $('start-stop-sync'); | 324 return $('start-stop-sync'); |
314 }, | 325 }, |
315 | 326 |
316 /** | 327 /** |
317 * Sets the label for the 'Show Home page' input. | 328 * Returns the <option> element with the given |value|. |
318 * @param {string} label The HTML of the input label. | 329 * @param {string} value One of 'none', 'ntp', 'url', 'choose'. |
319 * @private | 330 * @return {HTMLOptionElement} the specified <option> element. |
320 */ | 331 */ |
321 updateHomePageLabel_: function(label) { | 332 getHomePageOption_: function(value) { |
322 $('home-page-label').innerHTML = label; | 333 var select = $('home-page-select'); |
| 334 return select.querySelector('option[value=' + value + ']'); |
323 }, | 335 }, |
324 | 336 |
325 /** | 337 /** |
| 338 * Selects the <option> element with the given |value|. |
| 339 * @private |
| 340 */ |
| 341 selectHomePageOption_: function(value) { |
| 342 var select = $('home-page-select'); |
| 343 var option = this.getHomePageOption_(value); |
| 344 if (!option.selected) |
| 345 option.selected = true; |
| 346 }, |
| 347 |
| 348 /** |
| 349 * Event listener for the |change| event on the homepage <select> element. |
| 350 * @private |
| 351 */ |
| 352 onHomePageSelectChange_: function() { |
| 353 var option = $('home-page-select').value; |
| 354 if (option == 'choose') { |
| 355 OptionsPage.navigateToPage('homePageOverlay'); |
| 356 return; |
| 357 } |
| 358 |
| 359 var showHomeButton = (option != 'none'); |
| 360 Preferences.setBooleanPref('browser.show_home_button', showHomeButton); |
| 361 |
| 362 if (option == 'ntp') |
| 363 Preferences.setBooleanPref('homepage_is_newtabpage', true); |
| 364 else if (option == 'url') |
| 365 Preferences.setBooleanPref('homepage_is_newtabpage', false); |
| 366 }, |
| 367 |
| 368 /** |
| 369 * Event listener called when any homepage-related preferences change. |
| 370 * @private |
| 371 */ |
| 372 onHomePagePrefChanged_: function(event) { |
| 373 switch (event.type) { |
| 374 case 'homepage': |
| 375 this.getHomePageOption_('url').textContent = event.value['value']; |
| 376 break; |
| 377 case 'browser.show_home_button': |
| 378 this.showHomeButton_ = event.value['value']; |
| 379 break; |
| 380 case 'homepage_is_newtabpage': |
| 381 this.homePageIsNtp_ = event.value['value']; |
| 382 break; |
| 383 default: |
| 384 console.error('Unexpected pref change event:', event.type); |
| 385 } |
| 386 this.updateHomePageSelector(); |
| 387 }, |
| 388 |
| 389 /** |
| 390 * Updates the homepage <select> element to have the appropriate option |
| 391 * selected. |
| 392 */ |
| 393 updateHomePageSelector: function() { |
| 394 if (this.showHomeButton_) { |
| 395 if (this.homePageIsNtp_) |
| 396 this.selectHomePageOption_('ntp'); |
| 397 else |
| 398 this.selectHomePageOption_('url'); |
| 399 } else { |
| 400 this.selectHomePageOption_('none'); |
| 401 } |
| 402 }, |
| 403 |
| 404 /** |
| 405 * Sets the home page selector to the 'url' option.Called when user clicks |
| 406 * OK in the "Choose another..." dialog. |
| 407 */ |
| 408 homePageSelectUrl: function() { |
| 409 this.selectHomePageOption_('url'); |
| 410 }, |
| 411 |
| 412 /** |
326 * Called when the value of the instant.confirm_dialog_shown preference | 413 * Called when the value of the instant.confirm_dialog_shown preference |
327 * changes. Cache this value. | 414 * changes. Cache this value. |
328 * @param {Event} event Change event. | 415 * @param {Event} event Change event. |
329 * @private | 416 * @private |
330 */ | 417 */ |
331 onInstantConfirmDialogShownChanged_: function(event) { | 418 onInstantConfirmDialogShownChanged_: function(event) { |
332 this.instantConfirmDialogShown_ = event.value['value']; | 419 this.instantConfirmDialogShown_ = event.value['value']; |
333 }, | 420 }, |
334 | 421 |
335 /** | 422 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 var option = new Option(engine['name'], engine['index']); | 484 var option = new Option(engine['name'], engine['index']); |
398 if (defaultValue == option.value) | 485 if (defaultValue == option.value) |
399 defaultIndex = i; | 486 defaultIndex = i; |
400 engineSelect.appendChild(option); | 487 engineSelect.appendChild(option); |
401 } | 488 } |
402 if (defaultIndex >= 0) | 489 if (defaultIndex >= 0) |
403 engineSelect.selectedIndex = defaultIndex; | 490 engineSelect.selectedIndex = defaultIndex; |
404 }, | 491 }, |
405 | 492 |
406 /** | 493 /** |
407 * Returns true if the custom startup page control block should | |
408 * be enabled. | |
409 * @returns {boolean} Whether the startup page controls should be | |
410 * enabled. | |
411 */ | |
412 shouldEnableCustomStartupPageControls: function(pages) { | |
413 return $('startupShowPagesButton').checked && | |
414 !this.startup_pages_pref_.disabled; | |
415 }, | |
416 | |
417 /** | |
418 * Sets the enabled state of the custom startup page list controls | |
419 * based on the current startup radio button selection. | |
420 * @private | |
421 */ | |
422 updateCustomStartupPageControlStates_: function() { | |
423 var disable = !this.shouldEnableCustomStartupPageControls(); | |
424 var startupPagesList = $('startupPagesList'); | |
425 startupPagesList.disabled = disable; | |
426 startupPagesList.setAttribute('tabindex', disable ? -1 : 0); | |
427 // Explicitly set disabled state for input text elements. | |
428 var inputs = startupPagesList.querySelectorAll("input[type='text']"); | |
429 for (var i = 0; i < inputs.length; i++) | |
430 inputs[i].disabled = disable; | |
431 $('startupUseCurrentButton').disabled = disable; | |
432 }, | |
433 | |
434 /** | |
435 * Set the default search engine based on the popup selection. | 494 * Set the default search engine based on the popup selection. |
436 * @private | 495 * @private |
437 */ | 496 */ |
438 setDefaultSearchEngine_: function() { | 497 setDefaultSearchEngine_: function() { |
439 var engineSelect = $('defaultSearchEngine'); | 498 var engineSelect = $('defaultSearchEngine'); |
440 var selectedIndex = engineSelect.selectedIndex; | 499 var selectedIndex = engineSelect.selectedIndex; |
441 if (selectedIndex >= 0) { | 500 if (selectedIndex >= 0) { |
442 var selection = engineSelect.options[selectedIndex]; | 501 var selection = engineSelect.options[selectedIndex]; |
443 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | 502 chrome.send('setDefaultSearchEngine', [String(selection.value)]); |
444 } | 503 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 'setStartStopButtonVisible', | 639 'setStartStopButtonVisible', |
581 'setSyncActionLinkEnabled', | 640 'setSyncActionLinkEnabled', |
582 'setSyncActionLinkLabel', | 641 'setSyncActionLinkLabel', |
583 'setSyncEnabled', | 642 'setSyncEnabled', |
584 'setSyncSetupCompleted', | 643 'setSyncSetupCompleted', |
585 'setSyncStatus', | 644 'setSyncStatus', |
586 'setSyncStatusErrorVisible', | 645 'setSyncStatusErrorVisible', |
587 'setThemesResetButtonEnabled', | 646 'setThemesResetButtonEnabled', |
588 'updateAccountPicture', | 647 'updateAccountPicture', |
589 'updateAutocompleteSuggestions', | 648 'updateAutocompleteSuggestions', |
590 'updateHomePageLabel', | |
591 'updateSearchEngines', | 649 'updateSearchEngines', |
592 'updateStartupPages', | 650 'updateStartupPages', |
593 ].forEach(function(name) { | 651 ].forEach(function(name) { |
594 BrowserOptions[name] = function() { | 652 BrowserOptions[name] = function() { |
595 var instance = BrowserOptions.getInstance(); | 653 var instance = BrowserOptions.getInstance(); |
596 return instance[name + '_'].apply(instance, arguments); | 654 return instance[name + '_'].apply(instance, arguments); |
597 }; | 655 }; |
598 }); | 656 }); |
599 | 657 |
600 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, | 658 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, |
(...skipping 15 matching lines...) Expand all Loading... |
616 return BrowserOptions.getInstance().username_; | 674 return BrowserOptions.getInstance().username_; |
617 }; | 675 }; |
618 } | 676 } |
619 | 677 |
620 // Export | 678 // Export |
621 return { | 679 return { |
622 BrowserOptions: BrowserOptions | 680 BrowserOptions: BrowserOptions |
623 }; | 681 }; |
624 | 682 |
625 }); | 683 }); |
OLD | NEW |