OLD | NEW |
| (Empty) |
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 | |
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 if (cr.isMac) { | |
139 $('mac-passwords-warning').hidden = | |
140 !(localStrings.getString('macPasswordsWarning')); | |
141 } | |
142 | |
143 if (PersonalOptions.disableAutofillManagement()) { | |
144 $('autofill-settings').disabled = true; | |
145 | |
146 // Disable and turn off autofill. | |
147 var autofillEnabled = $('autofill-enabled'); | |
148 autofillEnabled.disabled = true; | |
149 autofillEnabled.checked = false; | |
150 cr.dispatchSimpleEvent(autofillEnabled, 'change'); | |
151 } | |
152 }, | |
153 | |
154 setSyncEnabled_: function(enabled) { | |
155 this.syncEnabled = enabled; | |
156 }, | |
157 | |
158 setAutoLoginVisible_ : function(visible) { | |
159 $('enable-auto-login-checkbox').hidden = !visible; | |
160 }, | |
161 | |
162 setSyncSetupCompleted_: function(completed) { | |
163 this.syncSetupCompleted = completed; | |
164 $('customize-sync').hidden = !completed; | |
165 }, | |
166 | |
167 setSyncStatus_: function(status) { | |
168 var statusSet = status != ''; | |
169 $('sync-overview').hidden = statusSet; | |
170 $('sync-status').hidden = !statusSet; | |
171 $('sync-status-text').innerHTML = status; | |
172 }, | |
173 | |
174 setSyncStatusErrorVisible_: function(visible) { | |
175 visible ? $('sync-status').classList.add('sync-error') : | |
176 $('sync-status').classList.remove('sync-error'); | |
177 }, | |
178 | |
179 setCustomizeSyncButtonEnabled_: function(enabled) { | |
180 $('customize-sync').disabled = !enabled; | |
181 }, | |
182 | |
183 setSyncActionLinkEnabled_: function(enabled) { | |
184 $('sync-action-link').disabled = !enabled; | |
185 }, | |
186 | |
187 setSyncActionLinkLabel_: function(status) { | |
188 $('sync-action-link').textContent = status; | |
189 | |
190 // link-button does is not zero-area when the contents of the button are | |
191 // empty, so explicitly hide the element. | |
192 $('sync-action-link').hidden = !status.length; | |
193 }, | |
194 | |
195 /** | |
196 * Display or hide the profiles section of the page. This is used for | |
197 * multi-profile settings. | |
198 * @param {boolean} visible True to show the section. | |
199 * @private | |
200 */ | |
201 setProfilesSectionVisible_: function(visible) { | |
202 $('profiles-section').hidden = !visible; | |
203 }, | |
204 | |
205 /** | |
206 * Get the selected profile item from the profile list. This also works | |
207 * correctly if the list is not displayed. | |
208 * @return {Object} the profile item object, or null if nothing is selected. | |
209 * @private | |
210 */ | |
211 getSelectedProfileItem_: function() { | |
212 var profilesList = $('profiles-list'); | |
213 if (profilesList.hidden) { | |
214 if (profilesList.dataModel.length > 0) | |
215 return profilesList.dataModel.item(0); | |
216 } else { | |
217 return profilesList.selectedItem; | |
218 } | |
219 return null; | |
220 }, | |
221 | |
222 /** | |
223 * Helper function to set the status of profile view buttons to disabled or | |
224 * enabled, depending on the number of profiles and selection status of the | |
225 * profiles list. | |
226 */ | |
227 setProfileViewButtonsStatus_: function() { | |
228 var profilesList = $('profiles-list'); | |
229 var selectedProfile = profilesList.selectedItem; | |
230 var hasSelection = selectedProfile != null; | |
231 var hasSingleProfile = profilesList.dataModel.length == 1; | |
232 $('profiles-manage').disabled = !hasSelection || | |
233 !selectedProfile.isCurrentProfile; | |
234 $('profiles-delete').disabled = !hasSelection && !hasSingleProfile; | |
235 }, | |
236 | |
237 /** | |
238 * Display the correct dialog layout, depending on how many profiles are | |
239 * available. | |
240 * @param {number} numProfiles The number of profiles to display. | |
241 */ | |
242 setProfileViewSingle_: function(numProfiles) { | |
243 var hasSingleProfile = numProfiles == 1; | |
244 $('profiles-list').hidden = hasSingleProfile; | |
245 $('profiles-single-message').hidden = !hasSingleProfile; | |
246 $('profiles-manage').hidden = hasSingleProfile; | |
247 $('profiles-delete').textContent = hasSingleProfile ? | |
248 templateData.profilesDeleteSingle : | |
249 templateData.profilesDelete; | |
250 }, | |
251 | |
252 /** | |
253 * Adds all |profiles| to the list. | |
254 * @param {Array.<Object>} An array of profile info objects. | |
255 * each object is of the form: | |
256 * profileInfo = { | |
257 * name: "Profile Name", | |
258 * iconURL: "chrome://path/to/icon/image", | |
259 * filePath: "/path/to/profile/data/on/disk", | |
260 * isCurrentProfile: false | |
261 * }; | |
262 */ | |
263 setProfilesInfo_: function(profiles) { | |
264 this.setProfileViewSingle_(profiles.length); | |
265 // add it to the list, even if the list is hidden so we can access it | |
266 // later. | |
267 $('profiles-list').dataModel = new ArrayDataModel(profiles); | |
268 this.setProfileViewButtonsStatus_(); | |
269 }, | |
270 | |
271 setStartStopButtonVisible_: function(visible) { | |
272 $('start-stop-sync').hidden = !visible; | |
273 }, | |
274 | |
275 setStartStopButtonEnabled_: function(enabled) { | |
276 $('start-stop-sync').disabled = !enabled; | |
277 }, | |
278 | |
279 setStartStopButtonLabel_: function(label) { | |
280 $('start-stop-sync').textContent = label; | |
281 }, | |
282 | |
283 setGtkThemeButtonEnabled_: function(enabled) { | |
284 if (!cr.isChromeOS && navigator.platform.match(/linux|BSD/i)) { | |
285 $('themes-GTK-button').disabled = !enabled; | |
286 } | |
287 }, | |
288 | |
289 setThemesResetButtonEnabled_: function(enabled) { | |
290 $('themes-reset').disabled = !enabled; | |
291 }, | |
292 | |
293 hideSyncSection_: function() { | |
294 $('sync-section').hidden = true; | |
295 }, | |
296 | |
297 /** | |
298 * Get the start/stop sync button DOM element. | |
299 * @return {DOMElement} The start/stop sync button. | |
300 * @private | |
301 */ | |
302 getStartStopSyncButton_: function() { | |
303 return $('start-stop-sync'); | |
304 }, | |
305 | |
306 /** | |
307 * (Re)loads IMG element with current user account picture. | |
308 */ | |
309 updateAccountPicture_: function() { | |
310 $('account-picture').src = | |
311 'chrome://userimage/' + this.username_ + | |
312 '?id=' + (new Date()).getTime(); | |
313 }, | |
314 }; | |
315 | |
316 /** | |
317 * Returns whether the user should be able to manage (view and edit) their | |
318 * stored passwords. Password management is disabled in guest mode. | |
319 * @return {boolean} True if password management should be disabled. | |
320 */ | |
321 PersonalOptions.disablePasswordManagement = function() { | |
322 return cr.commandLine && cr.commandLine.options['--bwsi']; | |
323 }; | |
324 | |
325 /** | |
326 * Returns whether the user should be able to manage autofill settings. | |
327 * @return {boolean} True if password management should be disabled. | |
328 */ | |
329 PersonalOptions.disableAutofillManagement = function() { | |
330 return cr.commandLine && cr.commandLine.options['--bwsi']; | |
331 }; | |
332 | |
333 if (cr.isChromeOS) { | |
334 /** | |
335 * Returns username (canonical email) of the user logged in (ChromeOS only). | |
336 * @return {string} user email. | |
337 */ | |
338 PersonalOptions.getLoggedInUsername = function() { | |
339 return PersonalOptions.getInstance().username_; | |
340 }; | |
341 } | |
342 | |
343 // Forward public APIs to private implementations. | |
344 [ | |
345 'getStartStopSyncButton', | |
346 'hideSyncSection', | |
347 'setAutoLoginVisible', | |
348 'setCustomizeSyncButtonEnabled', | |
349 'setGtkThemeButtonEnabled', | |
350 'setProfilesInfo', | |
351 'setProfilesSectionVisible', | |
352 'setStartStopButtonEnabled', | |
353 'setStartStopButtonLabel', | |
354 'setStartStopButtonVisible', | |
355 'setSyncActionLinkEnabled', | |
356 'setSyncActionLinkLabel', | |
357 'setSyncEnabled', | |
358 'setSyncSetupCompleted', | |
359 'setSyncStatus', | |
360 'setSyncStatusErrorVisible', | |
361 'setThemesResetButtonEnabled', | |
362 'updateAccountPicture', | |
363 ].forEach(function(name) { | |
364 PersonalOptions[name] = function() { | |
365 var instance = PersonalOptions.getInstance(); | |
366 return instance[name + '_'].apply(instance, arguments); | |
367 }; | |
368 }); | |
369 | |
370 // Export | |
371 return { | |
372 PersonalOptions: PersonalOptions | |
373 }; | |
374 | |
375 }); | |
OLD | NEW |