// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. cr.define('options', function() { var OptionsPage = options.OptionsPage; var ArrayDataModel = cr.ui.ArrayDataModel; // State variables. var syncEnabled = false; var syncSetupCompleted = false; /** * Encapsulated handling of personal options page. * @constructor */ function PersonalOptions() { OptionsPage.call(this, 'personal', templateData.personalPageTabTitle, 'personal-page'); if (cr.isChromeOS) { // Email of the currently logged in user (or |kGuestUser|). this.userEmail_ = localStrings.getString('userEmail'); } } cr.addSingletonGetter(PersonalOptions); PersonalOptions.prototype = { // Inherit PersonalOptions from OptionsPage. __proto__: options.OptionsPage.prototype, // Initialize PersonalOptions page. initializePage: function() { // Call base class implementation to start preference initialization. OptionsPage.prototype.initializePage.call(this); var self = this; // Sync. $('sync-action-link').onclick = function(event) { SyncSetupOverlay.showErrorUI(); }; $('start-stop-sync').onclick = function(event) { if (self.syncSetupCompleted) SyncSetupOverlay.showStopSyncingUI(); else SyncSetupOverlay.showSetupUI(); }; $('customize-sync').onclick = function(event) { SyncSetupOverlay.showSetupUI(); }; // Profiles. var profilesList = $('profiles-list'); options.personal_options.ProfileList.decorate(profilesList); profilesList.autoExpands = true; profilesList.onchange = function(event) { var selectedProfile = profilesList.selectedItem; var hasSelection = selectedProfile != null; var hasSingleProfile = profilesList.dataModel.length == 1; $('profiles-manage').disabled = !hasSelection; $('profiles-delete').disabled = !hasSingleProfile && !hasSelection; }; $('profiles-create').onclick = function(event) { chrome.send('createProfile'); }; $('profiles-manage').onclick = function(event) { var selectedProfile = self.getSelectedProfileItem_(); if (selectedProfile) ManageProfileOverlay.showManageDialog(selectedProfile); }; $('profiles-delete').onclick = function(event) { var selectedProfile = self.getSelectedProfileItem_(); if (selectedProfile) ManageProfileOverlay.showDeleteDialog(selectedProfile); }; // Passwords. $('manage-passwords').onclick = function(event) { OptionsPage.navigateToPage('passwords'); OptionsPage.showTab($('passwords-nav-tab')); chrome.send('coreOptionsUserMetricsAction', ['Options_ShowPasswordManager']); }; // Autofill. $('autofill-settings').onclick = function(event) { OptionsPage.navigateToPage('autofill'); chrome.send('coreOptionsUserMetricsAction', ['Options_ShowAutofillSettings']); }; if (cr.isChromeOS && cr.commandLine.options['--bwsi']) { // Hide Autofill options for the guest user. $('autofill-section').hidden = true; } // Appearance. $('themes-reset').onclick = function(event) { chrome.send('themesReset'); }; if (!cr.isChromeOS) { $('import-data').onclick = function(event) { // Make sure that any previous import success message is hidden, and // we're showing the UI to import further data. $('import-data-configure').hidden = false; $('import-data-success').hidden = true; OptionsPage.navigateToPage('importData'); chrome.send('coreOptionsUserMetricsAction', ['Import_ShowDlg']); }; if ($('themes-GTK-button')) { $('themes-GTK-button').onclick = function(event) { chrome.send('themesSetGTK'); }; } } else { $('change-picture-button').onclick = function(event) { OptionsPage.navigateToPage('changePicture'); }; this.updateAccountPicture_(); if (cr.commandLine.options['--bwsi']) { // Disable the screen lock checkbox and change-picture-button in // guest mode. $('enable-screen-lock').disabled = true; $('change-picture-button').disabled = true; } } if (PersonalOptions.disablePasswordManagement()) { // Disable the Password Manager in guest mode. $('passwords-offersave').disabled = true; $('passwords-neversave').disabled = true; $('passwords-offersave').value = false; $('passwords-neversave').value = true; $('manage-passwords').disabled = true; } if (PersonalOptions.disableAutofillManagement()) { $('autofill-settings').disabled = true; // Disable and turn off autofill. var autofillEnabled = $('autofill-enabled'); autofillEnabled.disabled = true; autofillEnabled.checked = false; cr.dispatchSimpleEvent(autofillEnabled, 'change'); } }, setSyncEnabled_: function(enabled) { this.syncEnabled = enabled; }, setAutoLoginVisible_ : function(visible) { $('enable-auto-login-checkbox').hidden = !visible; }, setSyncSetupCompleted_: function(completed) { this.syncSetupCompleted = completed; $('customize-sync').hidden = !completed; }, setSyncStatus_: function(status) { var statusSet = status != ''; $('sync-overview').hidden = statusSet; $('sync-status').hidden = !statusSet; $('sync-status-text').innerHTML = status; }, setSyncStatusErrorVisible_: function(visible) { visible ? $('sync-status').classList.add('sync-error') : $('sync-status').classList.remove('sync-error'); }, setSyncActionLinkEnabled_: function(enabled) { $('sync-action-link').disabled = !enabled; }, setSyncActionLinkLabel_: function(status) { $('sync-action-link').textContent = status; // link-button does is not zero-area when the contents of the button are // empty, so explicitly hide the element. $('sync-action-link').hidden = !status.length; }, /** * Display or hide the profiles section of the page. This is used for * multi-profile settings. * @param {boolean} visible True to show the section. * @private */ setProfilesSectionVisible_: function(visible) { $('profiles-section').hidden = !visible; }, /** * Get the selected profile item from the profile list. This also works * correctly if the list is not displayed. * @return {Object} the profile item object, or null if nothing is selected. * @private */ getSelectedProfileItem_: function() { var profilesList = $('profiles-list'); if (profilesList.hidden) { if (profilesList.dataModel.length > 0) return profilesList.dataModel.item(0); } else { return profilesList.selectedItem; } return null; }, /** * Display the correct dialog layout, depending on how many profiles are * available. * @param {number} numProfiles The number of profiles to display. */ setProfileViewSingle_: function(numProfiles) { var hasSingleProfile = numProfiles == 1; $('profiles-list').hidden = hasSingleProfile; $('profiles-single-message').hidden = !hasSingleProfile; $('profiles-manage').hidden = hasSingleProfile; $('profiles-delete').textContent = hasSingleProfile ? templateData.profilesDeleteSingle : templateData.profilesDelete; }, /** * Adds all |profiles| to the list. * @param {Array.} An array of profile info objects. * each object is of the form: * profileInfo = { * name: "Profile Name", * iconURL: "chrome://path/to/icon/image", * filePath: "/path/to/profile/data/on/disk", * isCurrentProfile: false * }; */ setProfilesInfo_: function(profiles) { this.setProfileViewSingle_(profiles.length); // add it to the list, even if the list is hidden so we can access it // later. $('profiles-list').dataModel = new ArrayDataModel(profiles); }, setStartStopButtonVisible_: function(visible) { $('start-stop-sync').hidden = !visible; }, setStartStopButtonEnabled_: function(enabled) { $('start-stop-sync').disabled = !enabled; }, setStartStopButtonLabel_: function(label) { $('start-stop-sync').textContent = label; }, setGtkThemeButtonEnabled_: function(enabled) { if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { $('themes-GTK-button').disabled = !enabled; } }, setThemesResetButtonEnabled_: function(enabled) { $('themes-reset').disabled = !enabled; }, hideSyncSection_: function() { $('sync-section').hidden = true; }, /** * (Re)loads IMG element with current user account picture. */ updateAccountPicture_: function() { $('account-picture').src = 'chrome://userimage/' + this.userEmail_ + '?id=' + (new Date()).getTime(); }, }; /** * Returns whether the user should be able to manage (view and edit) their * stored passwords. Password management is disabled in guest mode. * @return {boolean} True if password management should be disabled. */ PersonalOptions.disablePasswordManagement = function() { return cr.commandLine.options['--bwsi']; }; /** * Returns whether the user should be able to manage autofill settings. * @return {boolean} True if password management should be disabled. */ PersonalOptions.disableAutofillManagement = function() { return cr.commandLine.options['--bwsi']; }; if (cr.isChromeOS) { /** * Returns email of the user logged in (ChromeOS only). * @return {string} user email. */ PersonalOptions.getLoggedInUserEmail = function() { return PersonalOptions.getInstance().userEmail_; }; } // Forward public APIs to private implementations. [ 'hideSyncSection', 'setAutoLoginVisible', 'setGtkThemeButtonEnabled', 'setProfilesInfo', 'setProfilesSectionVisible', 'setStartStopButtonEnabled', 'setStartStopButtonLabel', 'setStartStopButtonVisible', 'setSyncActionLinkEnabled', 'setSyncActionLinkLabel', 'setSyncEnabled', 'setSyncSetupCompleted', 'setSyncStatus', 'setSyncStatusErrorVisible', 'setThemesResetButtonEnabled', 'updateAccountPicture', ].forEach(function(name) { PersonalOptions[name] = function(value) { PersonalOptions.getInstance()[name + '_'](value); }; }); // Export return { PersonalOptions: PersonalOptions }; });