Chromium Code Reviews| Index: chrome/browser/resources/options2/browser_options.js |
| =================================================================== |
| --- chrome/browser/resources/options2/browser_options.js (revision 117054) |
| +++ chrome/browser/resources/options2/browser_options.js (working copy) |
| @@ -14,6 +14,11 @@ |
| OptionsPage.call(this, 'browser', |
| templateData.browserPageTabTitle, |
| 'browserPage'); |
| + if (cr.isChromeOS) { |
|
James Hawkins
2012/01/11 16:33:29
Can this not be done in initializePage()?
csilv
2012/01/11 18:47:08
Done.
|
| + // Username (canonical email) of the currently logged in user or |
| + // |kGuestUser| if a guest session is active. |
| + this.username_ = localStrings.getString('username'); |
| + } |
| } |
| cr.addSingletonGetter(BrowserOptions); |
| @@ -44,7 +49,9 @@ |
| // Call base class implementation to start preference initialization. |
| OptionsPage.prototype.initializePage.call(this); |
| - // Sync. |
| + var self = this; |
| + |
| + // Sync (Sign in) section. |
| $('sync-action-link').onclick = function(event) { |
| SyncSetupOverlay.showErrorUI(); |
| }; |
| @@ -58,26 +65,34 @@ |
| SyncSetupOverlay.showSetupUI(); |
| }; |
| - // Wire up controls. |
| + // On Startup section. |
| $('startupSetPages').onclick = function() { |
| OptionsPage.navigateToPage('startup'); |
| }; |
| + |
| + // Appearance section. |
|
James Hawkins
2012/01/11 16:33:29
Toolbar Appearance
|
| + $('change-home-page').onclick = function(event) { |
| + OptionsPage.navigateToPage('homePageOverlay'); |
| + }; |
| + $('themes-gallery').onclick = function(event) { |
| + window.open(localStrings.getString('themesGalleryURL')); |
| + }; |
| + $('themes-reset').onclick = function(event) { |
| + chrome.send('themesReset'); |
| + }; |
| + // Ensure that changes are committed when closing the page. |
| + window.addEventListener('unload', function() { |
| + if (document.activeElement == homepageField) |
| + homepageField.blur(); |
| + }); |
| + |
| + // Search section. |
| $('defaultSearchManageEnginesButton').onclick = function(event) { |
| OptionsPage.navigateToPage('searchEngines'); |
| chrome.send('coreOptionsUserMetricsAction', |
| ['Options_ManageSearchEngines']); |
| }; |
| - $('advancedOptionsButton').onclick = function(event) { |
| - OptionsPage.navigateToPage('advanced'); |
| - chrome.send('coreOptionsUserMetricsAction', |
| - ['Options_OpenUnderTheHood']); |
| - }; |
| $('defaultSearchEngine').onchange = this.setDefaultSearchEngine_; |
| - $('change-home-page').onclick = function(event) { |
| - OptionsPage.navigateToPage('homePageOverlay'); |
| - }; |
| - |
| - var self = this; |
| $('instantEnabledCheckbox').customChangeHandler = function(event) { |
| if (this.checked) { |
| if (self.instantConfirmDialogShown_) |
| @@ -89,16 +104,13 @@ |
| } |
| return true; |
| }; |
| - |
| $('instantFieldTrialCheckbox').addEventListener('change', |
| function(event) { |
| this.checked = true; |
| chrome.send('disableInstant'); |
| }); |
| - |
| Preferences.getInstance().addEventListener('instant.confirm_dialog_shown', |
| this.onInstantConfirmDialogShownChanged_.bind(this)); |
| - |
| Preferences.getInstance().addEventListener('instant.enabled', |
| this.onInstantEnabledChanged_.bind(this)); |
| @@ -108,21 +120,8 @@ |
| self.autocompleteList_.syncWidthToInput(); |
| }); |
| - // Ensure that changes are committed when closing the page. |
| - window.addEventListener('unload', function() { |
| - if (document.activeElement == homepageField) |
| - homepageField.blur(); |
| - }); |
| - |
| - if (!cr.isChromeOS) { |
| - $('defaultBrowserUseAsDefaultButton').onclick = function(event) { |
| - chrome.send('becomeDefaultBrowser'); |
| - }; |
| - } |
| - |
| - // Check if we are in the guest mode. |
| if (cr.commandLine && cr.commandLine.options['--bwsi']) { |
| - // Hide the startup section. |
| + // Hide the startup section in Guest mode. |
| $('startupSection').hidden = true; |
| } |
| @@ -132,6 +131,69 @@ |
| this.requestAutocompleteSuggestions_.bind(this); |
| $('main-content').appendChild(suggestionList); |
| this.autocompleteList_ = suggestionList; |
| + |
| + // Users section. |
| + var profilesList = $('profiles-list'); |
| + options.browser_options.ProfileList.decorate(profilesList); |
| + profilesList.autoExpands = true; |
| + |
| + profilesList.onchange = self.setProfileViewButtonsStatus_; |
| + $('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); |
| + }; |
| + |
| + if (cr.isChromeOS) { |
| + $('change-picture-button').onclick = function(event) { |
| + OptionsPage.navigateToPage('changePicture'); |
| + }; |
| + this.updateAccountPicture_(); |
| + |
| + if (cr.commandLine && 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; |
| + } |
| + } else { |
| + $('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'); |
| + }; |
| + } |
| + } |
| + |
| + // Default browser section. |
| + if (!cr.isChromeOS) { |
| + $('defaultBrowserUseAsDefaultButton').onclick = function(event) { |
| + chrome.send('becomeDefaultBrowser'); |
| + }; |
| + } |
| + |
| + // Under the hood section. |
| + $('advancedOptionsButton').onclick = function(event) { |
| + OptionsPage.navigateToPage('advanced'); |
| + chrome.send('coreOptionsUserMetricsAction', |
| + ['Options_OpenUnderTheHood']); |
| + }; |
| }, |
| setSyncEnabled_: function(enabled) { |
| @@ -369,6 +431,91 @@ |
| return; |
| list.suggestions = suggestions; |
| }, |
| + |
| + /** |
| + * 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; |
| + }, |
| + |
| + /** |
| + * Helper function to set the status of profile view buttons to disabled or |
| + * enabled, depending on the number of profiles and selection status of the |
| + * profiles list. |
| + */ |
| + setProfileViewButtonsStatus_: function() { |
| + var profilesList = $('profiles-list'); |
| + var selectedProfile = profilesList.selectedItem; |
| + var hasSelection = selectedProfile != null; |
| + var hasSingleProfile = profilesList.dataModel.length == 1; |
| + $('profiles-manage').disabled = !hasSelection || |
| + !selectedProfile.isCurrentProfile; |
| + $('profiles-delete').disabled = !hasSelection && !hasSingleProfile; |
| + }, |
| + |
| + /** |
| + * 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.<Object>} 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); |
| + this.setProfileViewButtonsStatus_(); |
| + }, |
| + |
| + setGtkThemeButtonEnabled_: function(enabled) { |
| + if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { |
| + $('themes-GTK-button').disabled = !enabled; |
| + } |
| + }, |
| + |
| + setThemesResetButtonEnabled_: function(enabled) { |
| + $('themes-reset').disabled = !enabled; |
| + }, |
| + |
| + /** |
| + * (Re)loads IMG element with current user account picture. |
| + */ |
| + updateAccountPicture_: function() { |
| + $('account-picture').src = |
| + 'chrome://userimage/' + this.username_ + |
| + '?id=' + (new Date()).getTime(); |
| + }, |
| }; |
| //Forward public APIs to private implementations. |
| @@ -377,6 +524,10 @@ |
| 'hideSyncSection', |
| 'setAutoLoginVisible', |
| 'setCustomizeSyncButtonEnabled', |
| + 'setGtkThemeButtonEnabled', |
| + 'setInstantFieldTrialStatus', |
| + 'setProfilesInfo', |
| + 'setProfilesSectionVisible', |
| 'setStartStopButtonEnabled', |
| 'setStartStopButtonLabel', |
| 'setStartStopButtonVisible', |
| @@ -386,12 +537,12 @@ |
| 'setSyncSetupCompleted', |
| 'setSyncStatus', |
| 'setSyncStatusErrorVisible', |
| - 'setProfilesSectionVisible', |
| + 'setThemesResetButtonEnabled', |
| + 'updateAccountPicture', |
| + 'updateAutocompleteSuggestions', |
| 'updateHomePageLabel', |
| 'updateSearchEngines', |
| 'updateStartupPages', |
| - 'updateAutocompleteSuggestions', |
| - 'setInstantFieldTrialStatus', |
| ].forEach(function(name) { |
| BrowserOptions[name] = function(value) { |
| return BrowserOptions.getInstance()[name + '_'](value); |
| @@ -407,6 +558,16 @@ |
| } |
| }; |
| + if (cr.isChromeOS) { |
| + /** |
| + * Returns username (canonical email) of the user logged in (ChromeOS only). |
| + * @return {string} user email. |
| + */ |
| + BrowserOptions.getLoggedInUsername = function() { |
|
James Hawkins
2012/01/11 16:33:29
Ugh, this smells to me. I'm not going to ask you
csilv
2012/01/11 18:47:08
Done.
|
| + return BrowserOptions.getInstance().username_; |
| + }; |
| + } |
| + |
| // Export |
| return { |
| BrowserOptions: BrowserOptions |