Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: chrome/browser/resources/options/managed_user_settings.js

Issue 11783008: Add a lock to the managed user settings page and require authentication for unlocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix problem with some WebUI tests. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 if (loadTimeData.getBoolean('managedUsersEnabled')) { 5 if (loadTimeData.getBoolean('managedUsersEnabled')) {
6 6
7 cr.define('options', function() { 7 cr.define('options', function() {
8 /** @const */ var OptionsPage = options.OptionsPage; 8 /** @const */ var OptionsPage = options.OptionsPage;
9 /** @const */ var SettingsDialog = options.SettingsDialog; 9 /** @const */ var SettingsDialog = options.SettingsDialog;
10 10
(...skipping 10 matching lines...) Expand all
21 this, 21 this,
22 'manageduser', 22 'manageduser',
23 loadTimeData.getString('managedUserSettingsPageTabTitle'), 23 loadTimeData.getString('managedUserSettingsPageTabTitle'),
24 'managed-user-settings-page', 24 'managed-user-settings-page',
25 $('managed-user-settings-confirm'), 25 $('managed-user-settings-confirm'),
26 $('managed-user-settings-cancel')); 26 $('managed-user-settings-cancel'));
27 } 27 }
28 28
29 cr.addSingletonGetter(ManagedUserSettings); 29 cr.addSingletonGetter(ManagedUserSettings);
30 30
31 // Represents the three possible authentication states.
32 var ManagedUserAuthentication = {
33 // The manager of the managed account is not authenticated.
34 UNAUTHENTICATED: 'unauthenticated',
35
36 // The authentication is currently being checked.
37 CHECKING: 'checking',
38
39 // The manager of the managed account is authenticated.
40 AUTHENTICATED: 'authenticated'
41 };
42
31 ManagedUserSettings.prototype = { 43 ManagedUserSettings.prototype = {
32 // Inherit from SettingsDialog. 44 // Inherit from SettingsDialog.
33 __proto__: SettingsDialog.prototype, 45 __proto__: SettingsDialog.prototype,
34 46
47 // The current authentication state of the manager of the managed account.
48 authenticationState: ManagedUserAuthentication.UNAUTHENTICATED,
49
50 // True if the local passphrase of the manager of the managed account is
51 // set. If it is not set, no authentication is required.
52 isPassphraseSet: false,
53
35 /** 54 /**
36 * Initialize the page. 55 * Initialize the page.
37 * @override 56 * @override
38 */ 57 */
39 initializePage: function() { 58 initializePage: function() {
40 // Call base class implementation to start preference initialization. 59 // Call base class implementation to start preference initialization.
41 SettingsDialog.prototype.initializePage.call(this); 60 SettingsDialog.prototype.initializePage.call(this);
42 61
43 $('get-content-packs-button').onclick = function(event) { 62 $('get-content-packs-button').onclick = function(event) {
44 window.open(loadTimeData.getString('getContentPacksURL')); 63 window.open(loadTimeData.getString('getContentPacksURL'));
45 }; 64 };
46 65
47 $('set-passphrase').onclick = function() { 66 $('set-passphrase').onclick = function() {
48 OptionsPage.navigateToPage('setPassphrase'); 67 OptionsPage.navigateToPage('setPassphrase');
49 }; 68 };
50 69
70 $('use-passphrase-checkbox').onclick = function() {
71 $('set-passphrase').disabled = !$('use-passphrase-checkbox').checked;
72 };
73
74 var self = this;
75 $('unlock-settings').onclick = function() {
76 if (self.authenticationState == ManagedUserAuthentication.CHECKING)
77 return;
78 chrome.send('displayPassphraseDialog',
79 ['options.ManagedUserSettings.isAuthenticated']);
80 self.authenticationState = ManagedUserAuthentication.CHECKING;
81 };
51 }, 82 },
83
52 /** @override */ 84 /** @override */
53 handleConfirm: function() { 85 handleConfirm: function() {
86 if ($('use-passphrase-checkbox').checked && !this.isPassphraseSet) {
87 OptionsPage.navigateToPage('setPassphrase');
88 return;
89 }
90 if (!$('use-passphrase-checkbox').checked)
91 chrome.send('resetPassphrase');
54 chrome.send('confirmManagedUserSettings'); 92 chrome.send('confirmManagedUserSettings');
55 SettingsDialog.prototype.handleConfirm.call(this); 93 SettingsDialog.prototype.handleConfirm.call(this);
56 }, 94 },
95
96 // Enables or disables all controls based on the authentication state of
97 // the managed user. If |enable| is true, the controls will be enabled.
98 enableControls: function(enable) {
99 $('set-passphrase').disabled = !enable;
100 $('get-content-packs-button').disabled = !enable;
101 $('contentpacks-allow').setDisabled('notManagedUserModifiable', !enable);
102 $('contentpacks-warn').setDisabled('notManagedUserModifiable', !enable);
103 $('contentpacks-block').setDisabled('notManagedUserModifiable', !enable);
104 $('safe-search-checkbox').setDisabled(
105 'notManagedUserModifiable', !enable);
106 // TODO(akuegel): Add disable-signin-checkbox and
107 // disable-history-deletion-checkbox once these features are implemented
108 $('use-passphrase-checkbox').disabled = !enable;
109 $('unlock-settings').disabled = enable;
110 },
111
112 // Is called when the passphrase dialog is closed. |success| is true
113 // if the authentication was successful.
114 isAuthenticated_: function(success) {
115 if (success) {
116 this.authenticationState = ManagedUserAuthentication.AUTHENTICATED;
117 this.enableControls(true);
118 } else {
119 this.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED;
120 }
121 },
122
123 // Reset the authentication to UNAUTHENTICATED when the managed user
124 // settings dialog is closed.
125 didClosePage: function() {
126 // Reset the authentication of the custodian.
127 this.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED;
128 chrome.send('endAuthentication');
129 },
130 };
131
132 // Is called when the page is initialized. |hasPassphrase| is true if there
133 // is a local passphrase required to unlock the controls of the page.
134 // Also, the "use passphrase" checkbox will be initialized accordingly.
135 ManagedUserSettings.initializeSetPassphraseButton = function(hasPassphrase) {
136 $('set-passphrase').disabled = !hasPassphrase;
137 $('use-passphrase-checkbox').checked = hasPassphrase;
138 var instance = ManagedUserSettings.getInstance();
139 instance.isPassphraseSet = hasPassphrase;
140 if (hasPassphrase) {
141 instance.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED;
142 instance.enableControls(false);
143 } else {
144 instance.authenticationState = ManagedUserAuthentication.AUTHENTICATED;
145 $('unlock-settings').disabled = true;
146 }
147 };
148
149 // Is called when the passphrase dialog is closed. |success| is true
150 // if the authentication was successful.
151 ManagedUserSettings.isAuthenticated = function(success) {
152 ManagedUserSettings.getInstance().isAuthenticated_(success);
153 };
154
155 // Is called whenever the local passphrase has changed. |isPassphraseSet|
156 // is true if the local passphrase is non-empty.
157 ManagedUserSettings.passphraseChanged = function(isPassphraseSet) {
158 ManagedUserSettings.getInstance().isPassphraseSet = isPassphraseSet;
57 }; 159 };
58 160
59 var ManagedUserSettingsForTesting = { 161 var ManagedUserSettingsForTesting = {
60 getSetPassphraseButton: function() { 162 getSetPassphraseButton: function() {
61 return $('set-passphrase'); 163 return $('set-passphrase');
164 },
165 getUnlockButton: function() {
166 return $('unlock-settings');
62 } 167 }
63 }; 168 };
64 169
65 // Export 170 // Export
66 return { 171 return {
67 ManagedUserSettings: ManagedUserSettings, 172 ManagedUserSettings: ManagedUserSettings,
68 ManagedUserSettingsForTesting: ManagedUserSettingsForTesting 173 ManagedUserSettingsForTesting: ManagedUserSettingsForTesting,
174 ManagedUserAuthentication: ManagedUserAuthentication
69 }; 175 };
70 }); 176 });
71 177
72 } 178 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698