| 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 var RepeatingButton = cr.ui.RepeatingButton; |
| 8 | 9 |
| 9 // | 10 // |
| 10 // BrowserOptions class | 11 // BrowserOptions class |
| 11 // Encapsulated handling of browser options page. | 12 // Encapsulated handling of browser options page. |
| 12 // | 13 // |
| 13 function BrowserOptions() { | 14 function BrowserOptions() { |
| 14 OptionsPage.call(this, 'browser', | 15 OptionsPage.call(this, 'browser', |
| 15 templateData.browserPageTabTitle, | 16 templateData.browserPageTabTitle, |
| 16 'browserPage'); | 17 'browserPage'); |
| 17 } | 18 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 $('change-home-page').onclick = function(event) { | 70 $('change-home-page').onclick = function(event) { |
| 70 OptionsPage.navigateToPage('homePageOverlay'); | 71 OptionsPage.navigateToPage('homePageOverlay'); |
| 71 }; | 72 }; |
| 72 $('themes-gallery').onclick = function(event) { | 73 $('themes-gallery').onclick = function(event) { |
| 73 window.open(localStrings.getString('themesGalleryURL')); | 74 window.open(localStrings.getString('themesGalleryURL')); |
| 74 }; | 75 }; |
| 75 $('themes-reset').onclick = function(event) { | 76 $('themes-reset').onclick = function(event) { |
| 76 chrome.send('themesReset'); | 77 chrome.send('themesReset'); |
| 77 }; | 78 }; |
| 78 | 79 |
| 80 // Device section (ChromeOS only). |
| 81 if (cr.isChromeOS) { |
| 82 $('keyboard-settings-button').onclick = function(event) { |
| 83 OptionsPage.navigateToPage('keyboard-overlay'); |
| 84 }; |
| 85 $('pointer-settings-button').onclick = function(event) { |
| 86 OptionsPage.navigateToPage('pointer-overlay'); |
| 87 }; |
| 88 this.initBrightnessButton_('brightness-decrease-button', |
| 89 'decreaseScreenBrightness'); |
| 90 this.initBrightnessButton_('brightness-increase-button', |
| 91 'increaseScreenBrightness'); |
| 92 } |
| 93 |
| 79 // Search section. | 94 // Search section. |
| 80 $('defaultSearchManageEnginesButton').onclick = function(event) { | 95 $('defaultSearchManageEnginesButton').onclick = function(event) { |
| 81 OptionsPage.navigateToPage('searchEngines'); | 96 OptionsPage.navigateToPage('searchEngines'); |
| 82 chrome.send('coreOptionsUserMetricsAction', | 97 chrome.send('coreOptionsUserMetricsAction', |
| 83 ['Options_ManageSearchEngines']); | 98 ['Options_ManageSearchEngines']); |
| 84 }; | 99 }; |
| 85 $('defaultSearchEngine').onchange = this.setDefaultSearchEngine_; | 100 $('defaultSearchEngine').onchange = this.setDefaultSearchEngine_; |
| 86 $('instantEnabledCheckbox').customChangeHandler = function(event) { | 101 $('instantEnabledCheckbox').customChangeHandler = function(event) { |
| 87 if (this.checked) { | 102 if (this.checked) { |
| 88 if (self.instantConfirmDialogShown_) | 103 if (self.instantConfirmDialogShown_) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 198 } |
| 184 | 199 |
| 185 // Under the hood section. | 200 // Under the hood section. |
| 186 $('advancedOptionsButton').onclick = function(event) { | 201 $('advancedOptionsButton').onclick = function(event) { |
| 187 OptionsPage.navigateToPage('advanced'); | 202 OptionsPage.navigateToPage('advanced'); |
| 188 chrome.send('coreOptionsUserMetricsAction', | 203 chrome.send('coreOptionsUserMetricsAction', |
| 189 ['Options_OpenUnderTheHood']); | 204 ['Options_OpenUnderTheHood']); |
| 190 }; | 205 }; |
| 191 }, | 206 }, |
| 192 | 207 |
| 208 /** |
| 209 * Initializes a button for controlling screen brightness. |
| 210 * @param {string} id Button ID. |
| 211 * @param {string} callback Name of the callback function. |
| 212 */ |
| 213 initBrightnessButton_: function(id, callback) { |
| 214 var button = $(id); |
| 215 cr.ui.decorate(button, RepeatingButton); |
| 216 button.repeatInterval = 300; |
| 217 button.addEventListener(RepeatingButton.Event.BUTTON_HELD, function(e) { |
| 218 chrome.send(callback); |
| 219 }); |
| 220 }, |
| 221 |
| 193 setSyncEnabled_: function(enabled) { | 222 setSyncEnabled_: function(enabled) { |
| 194 this.syncEnabled = enabled; | 223 this.syncEnabled = enabled; |
| 195 }, | 224 }, |
| 196 | 225 |
| 197 setAutoLoginVisible_ : function(visible) { | 226 setAutoLoginVisible_: function(visible) { |
| 198 $('enable-auto-login-checkbox').hidden = !visible; | 227 $('enable-auto-login-checkbox').hidden = !visible; |
| 199 }, | 228 }, |
| 200 | 229 |
| 201 setSyncSetupCompleted_: function(completed) { | 230 setSyncSetupCompleted_: function(completed) { |
| 202 this.syncSetupCompleted = completed; | 231 this.syncSetupCompleted = completed; |
| 203 $('customize-sync').hidden = !completed; | 232 $('customize-sync').hidden = !completed; |
| 204 }, | 233 }, |
| 205 | 234 |
| 206 setSyncStatus_: function(status) { | 235 setSyncStatus_: function(status) { |
| 207 var statusSet = status != ''; | 236 var statusSet = status != ''; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 clearSearchEngines_: function() { | 360 clearSearchEngines_: function() { |
| 332 $('defaultSearchEngine').textContent = ''; | 361 $('defaultSearchEngine').textContent = ''; |
| 333 }, | 362 }, |
| 334 | 363 |
| 335 /** | 364 /** |
| 336 * Updates the search engine popup with the given entries. | 365 * Updates the search engine popup with the given entries. |
| 337 * @param {Array} engines List of available search engines. | 366 * @param {Array} engines List of available search engines. |
| 338 * @param {number} defaultValue The value of the current default engine. | 367 * @param {number} defaultValue The value of the current default engine. |
| 339 * @param {boolean} defaultManaged Whether the default search provider is | 368 * @param {boolean} defaultManaged Whether the default search provider is |
| 340 * managed. If true, the default search provider can't be changed. | 369 * managed. If true, the default search provider can't be changed. |
| 370 * @private |
| 341 */ | 371 */ |
| 342 updateSearchEngines_: function(engines, defaultValue, defaultManaged) { | 372 updateSearchEngines_: function(engines, defaultValue, defaultManaged) { |
| 343 this.clearSearchEngines_(); | 373 this.clearSearchEngines_(); |
| 344 engineSelect = $('defaultSearchEngine'); | 374 engineSelect = $('defaultSearchEngine'); |
| 345 engineSelect.disabled = defaultManaged; | 375 engineSelect.disabled = defaultManaged; |
| 346 engineCount = engines.length; | 376 engineCount = engines.length; |
| 347 var defaultIndex = -1; | 377 var defaultIndex = -1; |
| 348 for (var i = 0; i < engineCount; i++) { | 378 for (var i = 0; i < engineCount; i++) { |
| 349 var engine = engines[i]; | 379 var engine = engines[i]; |
| 350 var option = new Option(engine['name'], engine['index']); | 380 var option = new Option(engine['name'], engine['index']); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 379 startupPagesList.setAttribute('tabindex', disable ? -1 : 0); | 409 startupPagesList.setAttribute('tabindex', disable ? -1 : 0); |
| 380 // Explicitly set disabled state for input text elements. | 410 // Explicitly set disabled state for input text elements. |
| 381 var inputs = startupPagesList.querySelectorAll("input[type='text']"); | 411 var inputs = startupPagesList.querySelectorAll("input[type='text']"); |
| 382 for (var i = 0; i < inputs.length; i++) | 412 for (var i = 0; i < inputs.length; i++) |
| 383 inputs[i].disabled = disable; | 413 inputs[i].disabled = disable; |
| 384 $('startupUseCurrentButton').disabled = disable; | 414 $('startupUseCurrentButton').disabled = disable; |
| 385 }, | 415 }, |
| 386 | 416 |
| 387 /** | 417 /** |
| 388 * Set the default search engine based on the popup selection. | 418 * Set the default search engine based on the popup selection. |
| 419 * @private |
| 389 */ | 420 */ |
| 390 setDefaultSearchEngine_: function() { | 421 setDefaultSearchEngine_: function() { |
| 391 var engineSelect = $('defaultSearchEngine'); | 422 var engineSelect = $('defaultSearchEngine'); |
| 392 var selectedIndex = engineSelect.selectedIndex; | 423 var selectedIndex = engineSelect.selectedIndex; |
| 393 if (selectedIndex >= 0) { | 424 if (selectedIndex >= 0) { |
| 394 var selection = engineSelect.options[selectedIndex]; | 425 var selection = engineSelect.options[selectedIndex]; |
| 395 chrome.send('setDefaultSearchEngine', [String(selection.value)]); | 426 chrome.send('setDefaultSearchEngine', [String(selection.value)]); |
| 396 } | 427 } |
| 397 }, | 428 }, |
| 398 | 429 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } else { | 471 } else { |
| 441 return profilesList.selectedItem; | 472 return profilesList.selectedItem; |
| 442 } | 473 } |
| 443 return null; | 474 return null; |
| 444 }, | 475 }, |
| 445 | 476 |
| 446 /** | 477 /** |
| 447 * Helper function to set the status of profile view buttons to disabled or | 478 * Helper function to set the status of profile view buttons to disabled or |
| 448 * enabled, depending on the number of profiles and selection status of the | 479 * enabled, depending on the number of profiles and selection status of the |
| 449 * profiles list. | 480 * profiles list. |
| 481 * @private |
| 450 */ | 482 */ |
| 451 setProfileViewButtonsStatus_: function() { | 483 setProfileViewButtonsStatus_: function() { |
| 452 var profilesList = $('profiles-list'); | 484 var profilesList = $('profiles-list'); |
| 453 var selectedProfile = profilesList.selectedItem; | 485 var selectedProfile = profilesList.selectedItem; |
| 454 var hasSelection = selectedProfile != null; | 486 var hasSelection = selectedProfile != null; |
| 455 var hasSingleProfile = profilesList.dataModel.length == 1; | 487 var hasSingleProfile = profilesList.dataModel.length == 1; |
| 456 $('profiles-manage').disabled = !hasSelection || | 488 $('profiles-manage').disabled = !hasSelection || |
| 457 !selectedProfile.isCurrentProfile; | 489 !selectedProfile.isCurrentProfile; |
| 458 $('profiles-delete').disabled = !hasSelection && !hasSingleProfile; | 490 $('profiles-delete').disabled = !hasSelection && !hasSingleProfile; |
| 459 }, | 491 }, |
| 460 | 492 |
| 461 /** | 493 /** |
| 462 * Display the correct dialog layout, depending on how many profiles are | 494 * Display the correct dialog layout, depending on how many profiles are |
| 463 * available. | 495 * available. |
| 464 * @param {number} numProfiles The number of profiles to display. | 496 * @param {number} numProfiles The number of profiles to display. |
| 497 * @private |
| 465 */ | 498 */ |
| 466 setProfileViewSingle_: function(numProfiles) { | 499 setProfileViewSingle_: function(numProfiles) { |
| 467 var hasSingleProfile = numProfiles == 1; | 500 var hasSingleProfile = numProfiles == 1; |
| 468 $('profiles-list').hidden = hasSingleProfile; | 501 $('profiles-list').hidden = hasSingleProfile; |
| 469 $('profiles-single-message').hidden = !hasSingleProfile; | 502 $('profiles-single-message').hidden = !hasSingleProfile; |
| 470 $('profiles-manage').hidden = hasSingleProfile; | 503 $('profiles-manage').hidden = hasSingleProfile; |
| 471 $('profiles-delete').textContent = hasSingleProfile ? | 504 $('profiles-delete').textContent = hasSingleProfile ? |
| 472 templateData.profilesDeleteSingle : | 505 templateData.profilesDeleteSingle : |
| 473 templateData.profilesDelete; | 506 templateData.profilesDelete; |
| 474 }, | 507 }, |
| 475 | 508 |
| 476 /** | 509 /** |
| 477 * Adds all |profiles| to the list. | 510 * Adds all |profiles| to the list. |
| 478 * @param {Array.<Object>} An array of profile info objects. | 511 * @param {Array.<Object>} An array of profile info objects. |
| 479 * each object is of the form: | 512 * each object is of the form: |
| 480 * profileInfo = { | 513 * profileInfo = { |
| 481 * name: "Profile Name", | 514 * name: "Profile Name", |
| 482 * iconURL: "chrome://path/to/icon/image", | 515 * iconURL: "chrome://path/to/icon/image", |
| 483 * filePath: "/path/to/profile/data/on/disk", | 516 * filePath: "/path/to/profile/data/on/disk", |
| 484 * isCurrentProfile: false | 517 * isCurrentProfile: false |
| 485 * }; | 518 * }; |
| 519 * @private |
| 486 */ | 520 */ |
| 487 setProfilesInfo_: function(profiles) { | 521 setProfilesInfo_: function(profiles) { |
| 488 this.setProfileViewSingle_(profiles.length); | 522 this.setProfileViewSingle_(profiles.length); |
| 489 // add it to the list, even if the list is hidden so we can access it | 523 // add it to the list, even if the list is hidden so we can access it |
| 490 // later. | 524 // later. |
| 491 $('profiles-list').dataModel = new ArrayDataModel(profiles); | 525 $('profiles-list').dataModel = new ArrayDataModel(profiles); |
| 492 this.setProfileViewButtonsStatus_(); | 526 this.setProfileViewButtonsStatus_(); |
| 493 }, | 527 }, |
| 494 | 528 |
| 495 setGtkThemeButtonEnabled_: function(enabled) { | 529 setGtkThemeButtonEnabled_: function(enabled) { |
| 496 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { | 530 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { |
| 497 $('themes-GTK-button').disabled = !enabled; | 531 $('themes-GTK-button').disabled = !enabled; |
| 498 } | 532 } |
| 499 }, | 533 }, |
| 500 | 534 |
| 501 setThemesResetButtonEnabled_: function(enabled) { | 535 setThemesResetButtonEnabled_: function(enabled) { |
| 502 $('themes-reset').disabled = !enabled; | 536 $('themes-reset').disabled = !enabled; |
| 503 }, | 537 }, |
| 504 | 538 |
| 505 /** | 539 /** |
| 506 * (Re)loads IMG element with current user account picture. | 540 * (Re)loads IMG element with current user account picture. |
| 507 */ | 541 */ |
| 508 updateAccountPicture_: function() { | 542 updateAccountPicture_: function() { |
| 509 $('account-picture').src = | 543 $('account-picture').src = |
| 510 'chrome://userimage/' + this.username_ + | 544 'chrome://userimage/' + this.username_ + |
| 511 '?id=' + (new Date()).getTime(); | 545 '?id=' + (new Date()).getTime(); |
| 512 }, | 546 }, |
| 547 |
| 548 /** |
| 549 * Displays the touchpad controls section when we detect a touchpad, hides |
| 550 * it otherwise. |
| 551 * @param {boolean} show Whether or not to show the controls. |
| 552 * @private |
| 553 */ |
| 554 showTouchpadControls_: function() { |
| 555 $('touchpad-controls').hidden = !show; |
| 556 }, |
| 557 |
| 558 /** |
| 559 * Displays the mouse controls section when we detect a mouse, hides it |
| 560 * otherwise. |
| 561 * @param {boolean} show Whether or not to show the controls. |
| 562 * @private |
| 563 */ |
| 564 showMouseControls_: function(show) { |
| 565 $('mouse-controls').hidden = !show; |
| 566 }, |
| 513 }; | 567 }; |
| 514 | 568 |
| 515 //Forward public APIs to private implementations. | 569 //Forward public APIs to private implementations. |
| 516 [ | 570 [ |
| 517 'getStartStopSyncButton', | 571 'getStartStopSyncButton', |
| 518 'hideSyncSection', | 572 'hideSyncSection', |
| 519 'setAutoLoginVisible', | 573 'setAutoLoginVisible', |
| 520 'setCustomizeSyncButtonEnabled', | 574 'setCustomizeSyncButtonEnabled', |
| 521 'setGtkThemeButtonEnabled', | 575 'setGtkThemeButtonEnabled', |
| 522 'setInstantFieldTrialStatus', | 576 'setInstantFieldTrialStatus', |
| 523 'setProfilesInfo', | 577 'setProfilesInfo', |
| 524 'setProfilesSectionVisible', | 578 'setProfilesSectionVisible', |
| 525 'setStartStopButtonEnabled', | 579 'setStartStopButtonEnabled', |
| 526 'setStartStopButtonLabel', | 580 'setStartStopButtonLabel', |
| 527 'setStartStopButtonVisible', | 581 'setStartStopButtonVisible', |
| 528 'setSyncActionLinkEnabled', | 582 'setSyncActionLinkEnabled', |
| 529 'setSyncActionLinkLabel', | 583 'setSyncActionLinkLabel', |
| 530 'setSyncEnabled', | 584 'setSyncEnabled', |
| 531 'setSyncSetupCompleted', | 585 'setSyncSetupCompleted', |
| 532 'setSyncStatus', | 586 'setSyncStatus', |
| 533 'setSyncStatusErrorVisible', | 587 'setSyncStatusErrorVisible', |
| 534 'setThemesResetButtonEnabled', | 588 'setThemesResetButtonEnabled', |
| 535 'updateAccountPicture', | 589 'updateAccountPicture', |
| 536 'updateAutocompleteSuggestions', | 590 'updateAutocompleteSuggestions', |
| 537 'updateHomePageLabel', | 591 'updateHomePageLabel', |
| 538 'updateSearchEngines', | 592 'updateSearchEngines', |
| 539 'updateStartupPages', | 593 'updateStartupPages', |
| 594 'showTouchpadControls', |
| 595 'showMouseControls', |
| 540 ].forEach(function(name) { | 596 ].forEach(function(name) { |
| 541 BrowserOptions[name] = function(value) { | 597 BrowserOptions[name] = function(value) { |
| 542 return BrowserOptions.getInstance()[name + '_'](value); | 598 return BrowserOptions.getInstance()[name + '_'](value); |
| 543 }; | 599 }; |
| 544 }); | 600 }); |
| 545 | 601 |
| 546 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, | 602 BrowserOptions.updateDefaultBrowserState = function(statusString, isDefault, |
| 547 canBeDefault) { | 603 canBeDefault) { |
| 548 if (!cr.isChromeOS) { | 604 if (!cr.isChromeOS) { |
| 549 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, | 605 BrowserOptions.getInstance().updateDefaultBrowserState_(statusString, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 562 return BrowserOptions.getInstance().username_; | 618 return BrowserOptions.getInstance().username_; |
| 563 }; | 619 }; |
| 564 } | 620 } |
| 565 | 621 |
| 566 // Export | 622 // Export |
| 567 return { | 623 return { |
| 568 BrowserOptions: BrowserOptions | 624 BrowserOptions: BrowserOptions |
| 569 }; | 625 }; |
| 570 | 626 |
| 571 }); | 627 }); |
| OLD | NEW |