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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 /** | 330 /** |
320 * Get the start/stop sync button DOM element. | 331 * Get the start/stop sync button DOM element. |
321 * @return {DOMElement} The start/stop sync button. | 332 * @return {DOMElement} The start/stop sync button. |
322 * @private | 333 * @private |
323 */ | 334 */ |
324 getStartStopSyncButton_: function() { | 335 getStartStopSyncButton_: function() { |
325 return $('start-stop-sync'); | 336 return $('start-stop-sync'); |
326 }, | 337 }, |
327 | 338 |
328 /** | 339 /** |
329 * Sets the label for the 'Show Home page' input. | 340 * Returns the <option> element with the given |value|. |
330 * @param {string} label The HTML of the input label. | 341 * @param {string} value One of 'none', 'ntp', 'url', 'choose'. |
331 * @private | 342 * @return {HTMLOptionElement} the specified <option> element. |
332 */ | 343 */ |
333 updateHomePageLabel_: function(label) { | 344 getHomePageOption_: function(value) { |
334 $('home-page-label').innerHTML = label; | 345 var select = $('home-page-select'); |
| 346 return select.querySelector('option[value=' + value + ']'); |
335 }, | 347 }, |
336 | 348 |
337 /** | 349 /** |
| 350 * Selects the <option> element with the given |value|. |
| 351 * @private |
| 352 */ |
| 353 selectHomePageOption_: function(value) { |
| 354 var select = $('home-page-select'); |
| 355 var option = this.getHomePageOption_(value); |
| 356 if (!option.selected) |
| 357 option.selected = true; |
| 358 }, |
| 359 |
| 360 /** |
| 361 * Event listener for the |change| event on the homepage <select> element. |
| 362 * @private |
| 363 */ |
| 364 onHomePageSelectChange_: function() { |
| 365 var option = $('home-page-select').value; |
| 366 if (option == 'choose') { |
| 367 OptionsPage.navigateToPage('homePageOverlay'); |
| 368 return; |
| 369 } |
| 370 |
| 371 var showHomeButton = (option != 'none'); |
| 372 Preferences.setBooleanPref('browser.show_home_button', showHomeButton); |
| 373 |
| 374 if (option == 'ntp') |
| 375 Preferences.setBooleanPref('homepage_is_newtabpage', true); |
| 376 else if (option == 'url') |
| 377 Preferences.setBooleanPref('homepage_is_newtabpage', false); |
| 378 }, |
| 379 |
| 380 /** |
| 381 * Event listener called when any homepage-related preferences change. |
| 382 * @private |
| 383 */ |
| 384 onHomePagePrefChanged_: function(event) { |
| 385 switch (event.type) { |
| 386 case 'homepage': |
| 387 this.getHomePageOption_('url').textContent = event.value['value']; |
| 388 break; |
| 389 case 'browser.show_home_button': |
| 390 this.showHomeButton_ = event.value['value']; |
| 391 break; |
| 392 case 'homepage_is_newtabpage': |
| 393 this.homePageIsNtp_ = event.value['value']; |
| 394 break; |
| 395 default: |
| 396 console.error('Unexpected pref change event:', event.type); |
| 397 } |
| 398 this.updateHomePageSelector(); |
| 399 }, |
| 400 |
| 401 /** |
| 402 * Updates the homepage <select> element to have the appropriate option |
| 403 * selected. |
| 404 */ |
| 405 updateHomePageSelector: function() { |
| 406 if (this.showHomeButton_) { |
| 407 if (this.homePageIsNtp_) |
| 408 this.selectHomePageOption_('ntp'); |
| 409 else |
| 410 this.selectHomePageOption_('url'); |
| 411 } else { |
| 412 this.selectHomePageOption_('none'); |
| 413 } |
| 414 }, |
| 415 |
| 416 /** |
| 417 * Sets the home page selector to the 'url' option.Called when user clicks |
| 418 * OK in the "Choose another..." dialog. |
| 419 */ |
| 420 homePageSelectUrl: function() { |
| 421 this.selectHomePageOption_('url'); |
| 422 }, |
| 423 |
| 424 /** |
338 * Called when the value of the instant.confirm_dialog_shown preference | 425 * Called when the value of the instant.confirm_dialog_shown preference |
339 * changes. Cache this value. | 426 * changes. Cache this value. |
340 * @param {Event} event Change event. | 427 * @param {Event} event Change event. |
341 * @private | 428 * @private |
342 */ | 429 */ |
343 onInstantConfirmDialogShownChanged_: function(event) { | 430 onInstantConfirmDialogShownChanged_: function(event) { |
344 this.instantConfirmDialogShown_ = event.value['value']; | 431 this.instantConfirmDialogShown_ = event.value['value']; |
345 }, | 432 }, |
346 | 433 |
347 /** | 434 /** |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 var option = new Option(engine['name'], engine['index']); | 518 var option = new Option(engine['name'], engine['index']); |
432 if (defaultValue == option.value) | 519 if (defaultValue == option.value) |
433 defaultIndex = i; | 520 defaultIndex = i; |
434 engineSelect.appendChild(option); | 521 engineSelect.appendChild(option); |
435 } | 522 } |
436 if (defaultIndex >= 0) | 523 if (defaultIndex >= 0) |
437 engineSelect.selectedIndex = defaultIndex; | 524 engineSelect.selectedIndex = defaultIndex; |
438 }, | 525 }, |
439 | 526 |
440 /** | 527 /** |
441 * Returns true if the custom startup page control block should | |
442 * be enabled. | |
443 * @returns {boolean} Whether the startup page controls should be | |
444 * enabled. | |
445 */ | |
446 shouldEnableCustomStartupPageControls: function(pages) { | |
447 return $('startupShowPagesButton').checked && | |
448 !this.startup_pages_pref_.disabled; | |
449 }, | |
450 | |
451 /** | |
452 * Sets the enabled state of the custom startup page list controls | |
453 * based on the current startup radio button selection. | |
454 * @private | |
455 */ | |
456 updateCustomStartupPageControlStates_: function() { | |
457 var disable = !this.shouldEnableCustomStartupPageControls(); | |
458 var startupPagesList = $('startupPagesList'); | |
459 startupPagesList.disabled = disable; | |
460 startupPagesList.setAttribute('tabindex', disable ? -1 : 0); | |
461 // Explicitly set disabled state for input text elements. | |
462 var inputs = startupPagesList.querySelectorAll("input[type='text']"); | |
463 for (var i = 0; i < inputs.length; i++) | |
464 inputs[i].disabled = disable; | |
465 $('startupUseCurrentButton').disabled = disable; | |
466 }, | |
467 | |
468 /** | |
469 * Set the default search engine based on the popup selection. | 528 * Set the default search engine based on the popup selection. |
470 * @private | 529 * @private |
471 */ | 530 */ |
472 setDefaultSearchEngine_: function() { | 531 setDefaultSearchEngine_: function() { |
473 var engineSelect = $('defaultSearchEngine'); | 532 var engineSelect = $('defaultSearchEngine'); |
474 var selectedIndex = engineSelect.selectedIndex; | 533 var selectedIndex = engineSelect.selectedIndex; |
475 if (selectedIndex >= 0) { | 534 if (selectedIndex >= 0) { |
476 var selection = engineSelect.options[selectedIndex]; | 535 var selection = engineSelect.options[selectedIndex]; |
477 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | 536 chrome.send('setDefaultSearchEngine', [String(selection.value)]); |
478 } | 537 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 'setStartStopButtonVisible', | 673 'setStartStopButtonVisible', |
615 'setSyncActionLinkEnabled', | 674 'setSyncActionLinkEnabled', |
616 'setSyncActionLinkLabel', | 675 'setSyncActionLinkLabel', |
617 'setSyncEnabled', | 676 'setSyncEnabled', |
618 'setSyncSetupCompleted', | 677 'setSyncSetupCompleted', |
619 'setSyncStatus', | 678 'setSyncStatus', |
620 'setSyncStatusErrorVisible', | 679 'setSyncStatusErrorVisible', |
621 'setThemesResetButtonEnabled', | 680 'setThemesResetButtonEnabled', |
622 'updateAccountPicture', | 681 'updateAccountPicture', |
623 'updateAutocompleteSuggestions', | 682 'updateAutocompleteSuggestions', |
624 'updateHomePageLabel', | |
625 'updateSearchEngines', | 683 'updateSearchEngines', |
626 'updateStartupPages', | 684 'updateStartupPages', |
627 ].forEach(function(name) { | 685 ].forEach(function(name) { |
628 BrowserOptions[name] = function() { | 686 BrowserOptions[name] = function() { |
629 var instance = BrowserOptions.getInstance(); | 687 var instance = BrowserOptions.getInstance(); |
630 return instance[name + '_'].apply(instance, arguments); | 688 return instance[name + '_'].apply(instance, arguments); |
631 }; | 689 }; |
632 }); | 690 }); |
633 | 691 |
634 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, | 692 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, |
(...skipping 15 matching lines...) Expand all Loading... |
650 return BrowserOptions.getInstance().username_; | 708 return BrowserOptions.getInstance().username_; |
651 }; | 709 }; |
652 } | 710 } |
653 | 711 |
654 // Export | 712 // Export |
655 return { | 713 return { |
656 BrowserOptions: BrowserOptions | 714 BrowserOptions: BrowserOptions |
657 }; | 715 }; |
658 | 716 |
659 }); | 717 }); |
OLD | NEW |