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 var OptionsPage = options.OptionsPage; | 6 var OptionsPage = options.OptionsPage; |
7 var ArrayDataModel = cr.ui.ArrayDataModel; | 7 var ArrayDataModel = cr.ui.ArrayDataModel; |
8 var RepeatingButton = cr.ui.RepeatingButton; | 8 var 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, 'settings', templateData.settingsTitle, | 15 OptionsPage.call(this, 'settings', templateData.settingsTitle, |
16 'settings'); | 16 'settings'); |
17 } | 17 } |
18 | 18 |
19 cr.addSingletonGetter(BrowserOptions); | 19 cr.addSingletonGetter(BrowserOptions); |
20 | 20 |
21 BrowserOptions.prototype = { | 21 BrowserOptions.prototype = { |
22 __proto__: options.OptionsPage.prototype, | 22 __proto__: options.OptionsPage.prototype, |
23 | 23 |
24 // State variables. | 24 // State variables. |
25 syncEnabled: false, | 25 syncEnabled: false, |
26 syncSetupCompleted: false, | 26 syncSetupCompleted: false, |
27 | 27 |
28 showHomeButton_: false, | |
29 homePageIsNtp_: false, | |
30 | |
31 /** | 28 /** |
32 * An autocomplete list that can be attached to the home page URL text field | 29 * An autocomplete list that can be attached to the homepage URL text field |
33 * during editing. | 30 * during editing. |
34 * @type {HTMLElement} | 31 * @type {HTMLElement} |
35 * @private | 32 * @private |
36 */ | 33 */ |
37 autocompleteList_: null, | 34 autocompleteList_: null, |
38 | 35 |
39 /** | 36 /** |
40 * The cached value of the instant.confirm_dialog_shown preference. | 37 * The cached value of the instant.confirm_dialog_shown preference. |
41 * @type {bool} | 38 * @type {bool} |
42 * @private | 39 * @private |
43 */ | 40 */ |
44 instantConfirmDialogShown_: false, | 41 instantConfirmDialogShown_: false, |
45 | 42 |
46 /** | 43 /** |
47 * @inheritDoc | 44 * @inheritDoc |
48 */ | 45 */ |
49 initializePage: function() { | 46 initializePage: function() { |
50 OptionsPage.prototype.initializePage.call(this); | 47 OptionsPage.prototype.initializePage.call(this); |
51 | 48 |
52 var self = this; | |
53 | |
54 // Sync (Sign in) section. | 49 // Sync (Sign in) section. |
55 $('sync-action-link').onclick = function(event) { | 50 $('sync-action-link').onclick = function(event) { |
56 SyncSetupOverlay.showErrorUI(); | 51 SyncSetupOverlay.showErrorUI(); |
57 }; | 52 }; |
58 $('start-stop-sync').onclick = function(event) { | 53 $('start-stop-sync').onclick = function(event) { |
59 if (self.syncSetupCompleted) | 54 if (self.syncSetupCompleted) |
60 SyncSetupOverlay.showStopSyncingUI(); | 55 SyncSetupOverlay.showStopSyncingUI(); |
61 else | 56 else |
62 SyncSetupOverlay.showSetupUI(); | 57 SyncSetupOverlay.showSetupUI(); |
63 }; | 58 }; |
64 $('customize-sync').onclick = function(event) { | 59 $('customize-sync').onclick = function(event) { |
65 SyncSetupOverlay.showSetupUI(); | 60 SyncSetupOverlay.showSetupUI(); |
66 }; | 61 }; |
67 | 62 |
68 // Internet connection section (ChromeOS only). | 63 // Internet connection section (ChromeOS only). |
69 if (cr.isChromeOS) { | 64 if (cr.isChromeOS) { |
70 $('internet-options-button').onclick = function(event) { | 65 $('internet-options-button').onclick = function(event) { |
71 OptionsPage.navigateToPage('internet'); | 66 OptionsPage.navigateToPage('internet'); |
72 chrome.send('coreOptionsUserMetricsAction', | 67 chrome.send('coreOptionsUserMetricsAction', |
73 ['Options_InternetOptions']); | 68 ['Options_InternetOptions']); |
74 }; | 69 }; |
75 } | 70 } |
76 | 71 |
77 // On Startup section. | 72 // On Startup section. |
78 $('startup-set-pages').onclick = function() { | 73 $('startup-set-pages').onclick = function() { |
79 OptionsPage.navigateToPage('startup'); | 74 OptionsPage.navigateToPage('startup'); |
80 }; | 75 }; |
81 | 76 |
82 // Appearance section. | 77 // Appearance section. |
83 $('home-page-select').addEventListener( | 78 $('change-home-page').onclick = function(event) { |
84 'change', this.onHomePageSelectChange_.bind(this)); | 79 OptionsPage.navigateToPage('homePageOverlay'); |
85 | 80 }; |
86 ['browser.show_home_button', | |
87 'homepage', | |
88 'homepage_is_newtabpage'].forEach(function(pref) { | |
89 Preferences.getInstance().addEventListener( | |
90 pref, | |
91 self.onHomePagePrefChanged_.bind(self)); | |
92 }); | |
93 | |
94 $('themes-gallery').onclick = function(event) { | 81 $('themes-gallery').onclick = function(event) { |
95 window.open(localStrings.getString('themesGalleryURL')); | 82 window.open(localStrings.getString('themesGalleryURL')); |
96 }; | 83 }; |
97 $('themes-reset').onclick = function(event) { | 84 $('themes-reset').onclick = function(event) { |
98 chrome.send('themesReset'); | 85 chrome.send('themesReset'); |
99 }; | 86 }; |
100 | 87 |
101 // Device section (ChromeOS only). | 88 // Device section (ChromeOS only). |
102 if (cr.isChromeOS) { | 89 if (cr.isChromeOS) { |
103 $('keyboard-settings-button').onclick = function(evt) { | 90 $('keyboard-settings-button').onclick = function(evt) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 this.onInstantEnabledChanged_.bind(this)); | 128 this.onInstantEnabledChanged_.bind(this)); |
142 Preferences.getInstance().addEventListener( | 129 Preferences.getInstance().addEventListener( |
143 "session.restore_on_startup", | 130 "session.restore_on_startup", |
144 this.onSessionRestoreSelectedChanged_.bind(this)); | 131 this.onSessionRestoreSelectedChanged_.bind(this)); |
145 Preferences.getInstance().addEventListener( | 132 Preferences.getInstance().addEventListener( |
146 "restore_session_state.dialog_shown", | 133 "restore_session_state.dialog_shown", |
147 this.onSessionRestoreDialogShownChanged_.bind(this)); | 134 this.onSessionRestoreDialogShownChanged_.bind(this)); |
148 | 135 |
149 // Text fields may change widths when the window changes size, so make | 136 // Text fields may change widths when the window changes size, so make |
150 // sure the suggestion list stays in sync. | 137 // sure the suggestion list stays in sync. |
| 138 var self = this; |
151 window.addEventListener('resize', function() { | 139 window.addEventListener('resize', function() { |
152 self.autocompleteList_.syncWidthToInput(); | 140 self.autocompleteList_.syncWidthToInput(); |
153 }); | 141 }); |
154 | 142 |
155 var suggestionList = new cr.ui.AutocompleteList(); | 143 var suggestionList = new cr.ui.AutocompleteList(); |
156 suggestionList.autoExpands = true; | 144 suggestionList.autoExpands = true; |
157 suggestionList.suggestionUpdateRequestCallback = | 145 suggestionList.suggestionUpdateRequestCallback = |
158 this.requestAutocompleteSuggestions_.bind(this); | 146 this.requestAutocompleteSuggestions_.bind(this); |
159 $('main-content').appendChild(suggestionList); | 147 $('main-content').appendChild(suggestionList); |
160 this.autocompleteList_ = suggestionList; | 148 this.autocompleteList_ = suggestionList; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 /** | 315 /** |
328 * Get the start/stop sync button DOM element. | 316 * Get the start/stop sync button DOM element. |
329 * @return {DOMElement} The start/stop sync button. | 317 * @return {DOMElement} The start/stop sync button. |
330 * @private | 318 * @private |
331 */ | 319 */ |
332 getStartStopSyncButton_: function() { | 320 getStartStopSyncButton_: function() { |
333 return $('start-stop-sync'); | 321 return $('start-stop-sync'); |
334 }, | 322 }, |
335 | 323 |
336 /** | 324 /** |
337 * Returns the <option> element with the given |value|. | 325 * Sets the label for the 'Show Home page' input. |
338 * @param {string} value One of 'none', 'ntp', 'url', 'choose'. | 326 * @param {string} label The HTML of the input label. |
339 * @return {HTMLOptionElement} the specified <option> element. | |
340 */ | |
341 getHomePageOption_: function(value) { | |
342 var select = $('home-page-select'); | |
343 return select.querySelector('option[value=' + value + ']'); | |
344 }, | |
345 | |
346 /** | |
347 * Selects the <option> element with the given |value|. | |
348 * @private | 327 * @private |
349 */ | 328 */ |
350 selectHomePageOption_: function(value) { | 329 updateHomePageLabel_: function(label) { |
351 var select = $('home-page-select'); | 330 $('home-page-label').innerHTML = label; |
352 var option = this.getHomePageOption_(value); | |
353 if (!option.selected) | |
354 option.selected = true; | |
355 }, | |
356 | |
357 /** | |
358 * Event listener for the |change| event on the homepage <select> element. | |
359 * @private | |
360 */ | |
361 onHomePageSelectChange_: function() { | |
362 var option = $('home-page-select').value; | |
363 if (option == 'choose') { | |
364 OptionsPage.navigateToPage('homePageOverlay'); | |
365 return; | |
366 } | |
367 | |
368 var showHomeButton = (option != 'none'); | |
369 Preferences.setBooleanPref('browser.show_home_button', showHomeButton); | |
370 | |
371 if (option == 'ntp') | |
372 Preferences.setBooleanPref('homepage_is_newtabpage', true); | |
373 else if (option == 'url') | |
374 Preferences.setBooleanPref('homepage_is_newtabpage', false); | |
375 }, | |
376 | |
377 /** | |
378 * Event listener called when any homepage-related preferences change. | |
379 * @private | |
380 */ | |
381 onHomePagePrefChanged_: function(event) { | |
382 switch (event.type) { | |
383 case 'homepage': | |
384 this.getHomePageOption_('url').textContent = event.value['value']; | |
385 break; | |
386 case 'browser.show_home_button': | |
387 this.showHomeButton_ = event.value['value']; | |
388 break; | |
389 case 'homepage_is_newtabpage': | |
390 this.homePageIsNtp_ = event.value['value']; | |
391 break; | |
392 default: | |
393 console.error('Unexpected pref change event:', event.type); | |
394 } | |
395 this.updateHomePageSelector(); | |
396 }, | |
397 | |
398 /** | |
399 * Updates the homepage <select> element to have the appropriate option | |
400 * selected. | |
401 */ | |
402 updateHomePageSelector: function() { | |
403 if (this.showHomeButton_) { | |
404 if (this.homePageIsNtp_) | |
405 this.selectHomePageOption_('ntp'); | |
406 else | |
407 this.selectHomePageOption_('url'); | |
408 } else { | |
409 this.selectHomePageOption_('none'); | |
410 } | |
411 }, | |
412 | |
413 /** | |
414 * Sets the home page selector to the 'url' option.Called when user clicks | |
415 * OK in the "Choose another..." dialog. | |
416 */ | |
417 homePageSelectUrl: function() { | |
418 this.selectHomePageOption_('url'); | |
419 }, | 331 }, |
420 | 332 |
421 /** | 333 /** |
422 * Called when the value of the instant.confirm_dialog_shown preference | 334 * Called when the value of the instant.confirm_dialog_shown preference |
423 * changes. Cache this value. | 335 * changes. Cache this value. |
424 * @param {Event} event Change event. | 336 * @param {Event} event Change event. |
425 * @private | 337 * @private |
426 */ | 338 */ |
427 onInstantConfirmDialogShownChanged_: function(event) { | 339 onInstantConfirmDialogShownChanged_: function(event) { |
428 this.instantConfirmDialogShown_ = event.value['value']; | 340 this.instantConfirmDialogShown_ = event.value['value']; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 var option = new Option(engine['name'], engine['index']); | 427 var option = new Option(engine['name'], engine['index']); |
516 if (defaultValue == option.value) | 428 if (defaultValue == option.value) |
517 defaultIndex = i; | 429 defaultIndex = i; |
518 engineSelect.appendChild(option); | 430 engineSelect.appendChild(option); |
519 } | 431 } |
520 if (defaultIndex >= 0) | 432 if (defaultIndex >= 0) |
521 engineSelect.selectedIndex = defaultIndex; | 433 engineSelect.selectedIndex = defaultIndex; |
522 }, | 434 }, |
523 | 435 |
524 /** | 436 /** |
| 437 * Returns true if the custom startup page control block should |
| 438 * be enabled. |
| 439 * @returns {boolean} Whether the startup page controls should be |
| 440 * enabled. |
| 441 */ |
| 442 shouldEnableCustomStartupPageControls: function(pages) { |
| 443 return $('startup-show-pages').checked && |
| 444 !this.startup_pages_pref_.disabled; |
| 445 }, |
| 446 |
| 447 /** |
| 448 * Sets the enabled state of the custom startup page list controls |
| 449 * based on the current startup radio button selection. |
| 450 * @private |
| 451 */ |
| 452 updateCustomStartupPageControlStates_: function() { |
| 453 var disable = !this.shouldEnableCustomStartupPageControls(); |
| 454 var startupPagesList = $('startupPagesList'); |
| 455 startupPagesList.disabled = disable; |
| 456 startupPagesList.setAttribute('tabindex', disable ? -1 : 0); |
| 457 // Explicitly set disabled state for input text elements. |
| 458 var inputs = startupPagesList.querySelectorAll("input[type='text']"); |
| 459 for (var i = 0; i < inputs.length; i++) |
| 460 inputs[i].disabled = disable; |
| 461 $('startupUseCurrentButton').disabled = disable; |
| 462 }, |
| 463 |
| 464 /** |
525 * Set the default search engine based on the popup selection. | 465 * Set the default search engine based on the popup selection. |
526 * @private | 466 * @private |
527 */ | 467 */ |
528 setDefaultSearchEngine_: function() { | 468 setDefaultSearchEngine_: function() { |
529 var engineSelect = $('default-search-engine'); | 469 var engineSelect = $('default-search-engine'); |
530 var selectedIndex = engineSelect.selectedIndex; | 470 var selectedIndex = engineSelect.selectedIndex; |
531 if (selectedIndex >= 0) { | 471 if (selectedIndex >= 0) { |
532 var selection = engineSelect.options[selectedIndex]; | 472 var selection = engineSelect.options[selectedIndex]; |
533 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | 473 chrome.send('setDefaultSearchEngine', [String(selection.value)]); |
534 } | 474 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 'setStartStopButtonVisible', | 610 'setStartStopButtonVisible', |
671 'setSyncActionLinkEnabled', | 611 'setSyncActionLinkEnabled', |
672 'setSyncActionLinkLabel', | 612 'setSyncActionLinkLabel', |
673 'setSyncEnabled', | 613 'setSyncEnabled', |
674 'setSyncSetupCompleted', | 614 'setSyncSetupCompleted', |
675 'setSyncStatus', | 615 'setSyncStatus', |
676 'setSyncStatusErrorVisible', | 616 'setSyncStatusErrorVisible', |
677 'setThemesResetButtonEnabled', | 617 'setThemesResetButtonEnabled', |
678 'updateAccountPicture', | 618 'updateAccountPicture', |
679 'updateAutocompleteSuggestions', | 619 'updateAutocompleteSuggestions', |
| 620 'updateHomePageLabel', |
680 'updateSearchEngines', | 621 'updateSearchEngines', |
681 'updateStartupPages', | 622 'updateStartupPages', |
682 ].forEach(function(name) { | 623 ].forEach(function(name) { |
683 BrowserOptions[name] = function() { | 624 BrowserOptions[name] = function() { |
684 var instance = BrowserOptions.getInstance(); | 625 var instance = BrowserOptions.getInstance(); |
685 return instance[name + '_'].apply(instance, arguments); | 626 return instance[name + '_'].apply(instance, arguments); |
686 }; | 627 }; |
687 }); | 628 }); |
688 | 629 |
689 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, | 630 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, |
(...skipping 14 matching lines...) Expand all Loading... |
704 BrowserOptions.getLoggedInUsername = function() { | 645 BrowserOptions.getLoggedInUsername = function() { |
705 return BrowserOptions.getInstance().username_; | 646 return BrowserOptions.getInstance().username_; |
706 }; | 647 }; |
707 } | 648 } |
708 | 649 |
709 // Export | 650 // Export |
710 return { | 651 return { |
711 BrowserOptions: BrowserOptions | 652 BrowserOptions: BrowserOptions |
712 }; | 653 }; |
713 }); | 654 }); |
OLD | NEW |