OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('options', function() { |
| 6 |
| 7 var OptionsPage = options.OptionsPage; |
| 8 var ArrayDataModel = cr.ui.ArrayDataModel; |
| 9 |
| 10 /** |
| 11 * Encapsulated handling of personal options page. |
| 12 * @constructor |
| 13 */ |
| 14 function PersonalOptions() { |
| 15 OptionsPage.call(this, 'personal', |
| 16 templateData.personalPageTabTitle, |
| 17 'personal-page'); |
| 18 if (cr.isChromeOS) { |
| 19 // Username (canonical email) of the currently logged in user or |
| 20 // |kGuestUser| if a guest session is active. |
| 21 this.username_ = localStrings.getString('username'); |
| 22 } |
| 23 } |
| 24 |
| 25 cr.addSingletonGetter(PersonalOptions); |
| 26 |
| 27 PersonalOptions.prototype = { |
| 28 // Inherit PersonalOptions from OptionsPage. |
| 29 __proto__: options.OptionsPage.prototype, |
| 30 |
| 31 // State variables. |
| 32 syncEnabled: false, |
| 33 syncSetupCompleted: false, |
| 34 |
| 35 // Initialize PersonalOptions page. |
| 36 initializePage: function() { |
| 37 // Call base class implementation to start preference initialization. |
| 38 OptionsPage.prototype.initializePage.call(this); |
| 39 |
| 40 var self = this; |
| 41 |
| 42 // Sync. |
| 43 $('sync-action-link').onclick = function(event) { |
| 44 SyncSetupOverlay.showErrorUI(); |
| 45 }; |
| 46 $('start-stop-sync').onclick = function(event) { |
| 47 if (self.syncSetupCompleted) |
| 48 SyncSetupOverlay.showStopSyncingUI(); |
| 49 else |
| 50 SyncSetupOverlay.showSetupUI(); |
| 51 }; |
| 52 $('customize-sync').onclick = function(event) { |
| 53 SyncSetupOverlay.showSetupUI(); |
| 54 }; |
| 55 |
| 56 // Profiles. |
| 57 var profilesList = $('profiles-list'); |
| 58 options.personal_options.ProfileList.decorate(profilesList); |
| 59 profilesList.autoExpands = true; |
| 60 |
| 61 profilesList.onchange = self.setProfileViewButtonsStatus_; |
| 62 $('profiles-create').onclick = function(event) { |
| 63 chrome.send('createProfile'); |
| 64 }; |
| 65 $('profiles-manage').onclick = function(event) { |
| 66 var selectedProfile = self.getSelectedProfileItem_(); |
| 67 if (selectedProfile) |
| 68 ManageProfileOverlay.showManageDialog(selectedProfile); |
| 69 }; |
| 70 $('profiles-delete').onclick = function(event) { |
| 71 var selectedProfile = self.getSelectedProfileItem_(); |
| 72 if (selectedProfile) |
| 73 ManageProfileOverlay.showDeleteDialog(selectedProfile); |
| 74 }; |
| 75 |
| 76 // Passwords. |
| 77 $('manage-passwords').onclick = function(event) { |
| 78 OptionsPage.navigateToPage('passwords'); |
| 79 OptionsPage.showTab($('passwords-nav-tab')); |
| 80 chrome.send('coreOptionsUserMetricsAction', |
| 81 ['Options_ShowPasswordManager']); |
| 82 }; |
| 83 |
| 84 // Autofill. |
| 85 $('autofill-settings').onclick = function(event) { |
| 86 OptionsPage.navigateToPage('autofill'); |
| 87 chrome.send('coreOptionsUserMetricsAction', |
| 88 ['Options_ShowAutofillSettings']); |
| 89 }; |
| 90 if (cr.isChromeOS && cr.commandLine && cr.commandLine.options['--bwsi']) { |
| 91 // Hide Autofill options for the guest user. |
| 92 $('autofill-section').hidden = true; |
| 93 } |
| 94 |
| 95 // Appearance. |
| 96 $('themes-reset').onclick = function(event) { |
| 97 chrome.send('themesReset'); |
| 98 }; |
| 99 |
| 100 if (!cr.isChromeOS) { |
| 101 $('import-data').onclick = function(event) { |
| 102 // Make sure that any previous import success message is hidden, and |
| 103 // we're showing the UI to import further data. |
| 104 $('import-data-configure').hidden = false; |
| 105 $('import-data-success').hidden = true; |
| 106 OptionsPage.navigateToPage('importData'); |
| 107 chrome.send('coreOptionsUserMetricsAction', ['Import_ShowDlg']); |
| 108 }; |
| 109 |
| 110 if ($('themes-GTK-button')) { |
| 111 $('themes-GTK-button').onclick = function(event) { |
| 112 chrome.send('themesSetGTK'); |
| 113 }; |
| 114 } |
| 115 } else { |
| 116 $('change-picture-button').onclick = function(event) { |
| 117 OptionsPage.navigateToPage('changePicture'); |
| 118 }; |
| 119 this.updateAccountPicture_(); |
| 120 |
| 121 if (cr.commandLine && cr.commandLine.options['--bwsi']) { |
| 122 // Disable the screen lock checkbox and change-picture-button in |
| 123 // guest mode. |
| 124 $('enable-screen-lock').disabled = true; |
| 125 $('change-picture-button').disabled = true; |
| 126 } |
| 127 } |
| 128 |
| 129 if (PersonalOptions.disablePasswordManagement()) { |
| 130 // Disable the Password Manager in guest mode. |
| 131 $('passwords-offersave').disabled = true; |
| 132 $('passwords-neversave').disabled = true; |
| 133 $('passwords-offersave').value = false; |
| 134 $('passwords-neversave').value = true; |
| 135 $('manage-passwords').disabled = true; |
| 136 } |
| 137 |
| 138 $('mac-passwords-warning').hidden = |
| 139 !(localStrings.getString('macPasswordsWarning')); |
| 140 |
| 141 if (PersonalOptions.disableAutofillManagement()) { |
| 142 $('autofill-settings').disabled = true; |
| 143 |
| 144 // Disable and turn off autofill. |
| 145 var autofillEnabled = $('autofill-enabled'); |
| 146 autofillEnabled.disabled = true; |
| 147 autofillEnabled.checked = false; |
| 148 cr.dispatchSimpleEvent(autofillEnabled, 'change'); |
| 149 } |
| 150 }, |
| 151 |
| 152 setSyncEnabled_: function(enabled) { |
| 153 this.syncEnabled = enabled; |
| 154 }, |
| 155 |
| 156 setAutoLoginVisible_ : function(visible) { |
| 157 $('enable-auto-login-checkbox').hidden = !visible; |
| 158 }, |
| 159 |
| 160 setSyncSetupCompleted_: function(completed) { |
| 161 this.syncSetupCompleted = completed; |
| 162 $('customize-sync').hidden = !completed; |
| 163 }, |
| 164 |
| 165 setSyncStatus_: function(status) { |
| 166 var statusSet = status != ''; |
| 167 $('sync-overview').hidden = statusSet; |
| 168 $('sync-status').hidden = !statusSet; |
| 169 $('sync-status-text').innerHTML = status; |
| 170 }, |
| 171 |
| 172 setSyncStatusErrorVisible_: function(visible) { |
| 173 visible ? $('sync-status').classList.add('sync-error') : |
| 174 $('sync-status').classList.remove('sync-error'); |
| 175 }, |
| 176 |
| 177 setCustomizeSyncButtonEnabled_: function(enabled) { |
| 178 $('customize-sync').disabled = !enabled; |
| 179 }, |
| 180 |
| 181 setSyncActionLinkEnabled_: function(enabled) { |
| 182 $('sync-action-link').disabled = !enabled; |
| 183 }, |
| 184 |
| 185 setSyncActionLinkLabel_: function(status) { |
| 186 $('sync-action-link').textContent = status; |
| 187 |
| 188 // link-button does is not zero-area when the contents of the button are |
| 189 // empty, so explicitly hide the element. |
| 190 $('sync-action-link').hidden = !status.length; |
| 191 }, |
| 192 |
| 193 /** |
| 194 * Display or hide the profiles section of the page. This is used for |
| 195 * multi-profile settings. |
| 196 * @param {boolean} visible True to show the section. |
| 197 * @private |
| 198 */ |
| 199 setProfilesSectionVisible_: function(visible) { |
| 200 $('profiles-section').hidden = !visible; |
| 201 }, |
| 202 |
| 203 /** |
| 204 * Get the selected profile item from the profile list. This also works |
| 205 * correctly if the list is not displayed. |
| 206 * @return {Object} the profile item object, or null if nothing is selected. |
| 207 * @private |
| 208 */ |
| 209 getSelectedProfileItem_: function() { |
| 210 var profilesList = $('profiles-list'); |
| 211 if (profilesList.hidden) { |
| 212 if (profilesList.dataModel.length > 0) |
| 213 return profilesList.dataModel.item(0); |
| 214 } else { |
| 215 return profilesList.selectedItem; |
| 216 } |
| 217 return null; |
| 218 }, |
| 219 |
| 220 /** |
| 221 * Helper function to set the status of profile view buttons to disabled or |
| 222 * enabled, depending on the number of profiles and selection status of the |
| 223 * profiles list. |
| 224 */ |
| 225 setProfileViewButtonsStatus_: function() { |
| 226 var profilesList = $('profiles-list'); |
| 227 var selectedProfile = profilesList.selectedItem; |
| 228 var hasSelection = selectedProfile != null; |
| 229 var hasSingleProfile = profilesList.dataModel.length == 1; |
| 230 $('profiles-manage').disabled = !hasSelection || |
| 231 !selectedProfile.isCurrentProfile; |
| 232 $('profiles-delete').disabled = !hasSelection && !hasSingleProfile; |
| 233 }, |
| 234 |
| 235 /** |
| 236 * Display the correct dialog layout, depending on how many profiles are |
| 237 * available. |
| 238 * @param {number} numProfiles The number of profiles to display. |
| 239 */ |
| 240 setProfileViewSingle_: function(numProfiles) { |
| 241 var hasSingleProfile = numProfiles == 1; |
| 242 $('profiles-list').hidden = hasSingleProfile; |
| 243 $('profiles-single-message').hidden = !hasSingleProfile; |
| 244 $('profiles-manage').hidden = hasSingleProfile; |
| 245 $('profiles-delete').textContent = hasSingleProfile ? |
| 246 templateData.profilesDeleteSingle : |
| 247 templateData.profilesDelete; |
| 248 }, |
| 249 |
| 250 /** |
| 251 * Adds all |profiles| to the list. |
| 252 * @param {Array.<Object>} An array of profile info objects. |
| 253 * each object is of the form: |
| 254 * profileInfo = { |
| 255 * name: "Profile Name", |
| 256 * iconURL: "chrome://path/to/icon/image", |
| 257 * filePath: "/path/to/profile/data/on/disk", |
| 258 * isCurrentProfile: false |
| 259 * }; |
| 260 */ |
| 261 setProfilesInfo_: function(profiles) { |
| 262 this.setProfileViewSingle_(profiles.length); |
| 263 // add it to the list, even if the list is hidden so we can access it |
| 264 // later. |
| 265 $('profiles-list').dataModel = new ArrayDataModel(profiles); |
| 266 this.setProfileViewButtonsStatus_(); |
| 267 }, |
| 268 |
| 269 setStartStopButtonVisible_: function(visible) { |
| 270 $('start-stop-sync').hidden = !visible; |
| 271 }, |
| 272 |
| 273 setStartStopButtonEnabled_: function(enabled) { |
| 274 $('start-stop-sync').disabled = !enabled; |
| 275 }, |
| 276 |
| 277 setStartStopButtonLabel_: function(label) { |
| 278 $('start-stop-sync').textContent = label; |
| 279 }, |
| 280 |
| 281 setGtkThemeButtonEnabled_: function(enabled) { |
| 282 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { |
| 283 $('themes-GTK-button').disabled = !enabled; |
| 284 } |
| 285 }, |
| 286 |
| 287 setThemesResetButtonEnabled_: function(enabled) { |
| 288 $('themes-reset').disabled = !enabled; |
| 289 }, |
| 290 |
| 291 hideSyncSection_: function() { |
| 292 $('sync-section').hidden = true; |
| 293 }, |
| 294 |
| 295 /** |
| 296 * Get the start/stop sync button DOM element. |
| 297 * @return {DOMElement} The start/stop sync button. |
| 298 * @private |
| 299 */ |
| 300 getStartStopSyncButton_: function() { |
| 301 return $('start-stop-sync'); |
| 302 }, |
| 303 |
| 304 /** |
| 305 * (Re)loads IMG element with current user account picture. |
| 306 */ |
| 307 updateAccountPicture_: function() { |
| 308 $('account-picture').src = |
| 309 'chrome://userimage/' + this.username_ + |
| 310 '?id=' + (new Date()).getTime(); |
| 311 }, |
| 312 }; |
| 313 |
| 314 /** |
| 315 * Returns whether the user should be able to manage (view and edit) their |
| 316 * stored passwords. Password management is disabled in guest mode. |
| 317 * @return {boolean} True if password management should be disabled. |
| 318 */ |
| 319 PersonalOptions.disablePasswordManagement = function() { |
| 320 return cr.commandLine && cr.commandLine.options['--bwsi']; |
| 321 }; |
| 322 |
| 323 /** |
| 324 * Returns whether the user should be able to manage autofill settings. |
| 325 * @return {boolean} True if password management should be disabled. |
| 326 */ |
| 327 PersonalOptions.disableAutofillManagement = function() { |
| 328 return cr.commandLine && cr.commandLine.options['--bwsi']; |
| 329 }; |
| 330 |
| 331 if (cr.isChromeOS) { |
| 332 /** |
| 333 * Returns username (canonical email) of the user logged in (ChromeOS only). |
| 334 * @return {string} user email. |
| 335 */ |
| 336 PersonalOptions.getLoggedInUsername = function() { |
| 337 return PersonalOptions.getInstance().username_; |
| 338 }; |
| 339 } |
| 340 |
| 341 // Forward public APIs to private implementations. |
| 342 [ |
| 343 'getStartStopSyncButton', |
| 344 'hideSyncSection', |
| 345 'setAutoLoginVisible', |
| 346 'setCustomizeSyncButtonEnabled', |
| 347 'setGtkThemeButtonEnabled', |
| 348 'setProfilesInfo', |
| 349 'setProfilesSectionVisible', |
| 350 'setStartStopButtonEnabled', |
| 351 'setStartStopButtonLabel', |
| 352 'setStartStopButtonVisible', |
| 353 'setSyncActionLinkEnabled', |
| 354 'setSyncActionLinkLabel', |
| 355 'setSyncEnabled', |
| 356 'setSyncSetupCompleted', |
| 357 'setSyncStatus', |
| 358 'setSyncStatusErrorVisible', |
| 359 'setThemesResetButtonEnabled', |
| 360 'updateAccountPicture', |
| 361 ].forEach(function(name) { |
| 362 PersonalOptions[name] = function(value) { |
| 363 return PersonalOptions.getInstance()[name + '_'](value); |
| 364 }; |
| 365 }); |
| 366 |
| 367 // Export |
| 368 return { |
| 369 PersonalOptions: PersonalOptions |
| 370 }; |
| 371 |
| 372 }); |
OLD | NEW |