OLD | NEW |
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; | |
10 | 9 |
11 ////////////////////////////////////////////////////////////////////////////// | 10 ////////////////////////////////////////////////////////////////////////////// |
12 // ManagedUserSettings class: | 11 // ManagedUserSettings class: |
13 | 12 |
14 /** | 13 /** |
15 * Encapsulated handling of the Managed User Settings page. | 14 * Encapsulated handling of the Managed User Settings page. |
16 * @constructor | 15 * @constructor |
17 * @class | 16 * @class |
18 */ | 17 */ |
19 function ManagedUserSettings() { | 18 function ManagedUserSettings() { |
20 SettingsDialog.call( | 19 OptionsPage.call( |
21 this, | 20 this, |
22 'manageduser', | 21 'manageduser', |
23 loadTimeData.getString('managedUserSettingsPageTabTitle'), | 22 loadTimeData.getString('managedUserSettingsPageTabTitle'), |
24 'managed-user-settings-page', | 23 'managed-user-settings-page'); |
25 $('managed-user-settings-confirm'), | |
26 $('managed-user-settings-cancel')); | |
27 } | 24 } |
28 | 25 |
29 cr.addSingletonGetter(ManagedUserSettings); | 26 cr.addSingletonGetter(ManagedUserSettings); |
30 | 27 |
31 // Represents the three possible authentication states. | 28 // Represents the three possible authentication states. |
32 var ManagedUserAuthentication = { | 29 var ManagedUserAuthentication = { |
33 // The manager of the managed account is not authenticated. | 30 // The manager of the managed account is not authenticated. |
34 UNAUTHENTICATED: 'unauthenticated', | 31 UNAUTHENTICATED: 'unauthenticated', |
35 | 32 |
36 // The authentication is currently being checked. | 33 // The authentication is currently being checked. |
37 CHECKING: 'checking', | 34 CHECKING: 'checking', |
38 | 35 |
39 // The manager of the managed account is authenticated. | 36 // The manager of the managed account is authenticated. |
40 AUTHENTICATED: 'authenticated' | 37 AUTHENTICATED: 'authenticated' |
41 }; | 38 }; |
42 | 39 |
43 ManagedUserSettings.prototype = { | 40 ManagedUserSettings.prototype = { |
44 // Inherit from SettingsDialog. | 41 // Inherit from OptionsPage. |
45 __proto__: SettingsDialog.prototype, | 42 __proto__: OptionsPage.prototype, |
46 | 43 |
47 // The current authentication state of the manager of the managed account. | 44 // The current authentication state of the manager of the managed account. |
48 authenticationState: ManagedUserAuthentication.UNAUTHENTICATED, | 45 authenticationState_: ManagedUserAuthentication.UNAUTHENTICATED, |
49 | 46 |
50 // True if the local passphrase of the manager of the managed account is | 47 get isAuthenticated() { |
51 // set. If it is not set, no authentication is required. | 48 return !cr.isChromeOS && |
52 isPassphraseSet: false, | 49 (this.authenticationState_ == |
| 50 ManagedUserAuthentication.AUTHENTICATED); |
| 51 }, |
53 | 52 |
54 /** | 53 /** @override */ |
55 * Initialize the page. | |
56 * @override | |
57 */ | |
58 initializePage: function() { | 54 initializePage: function() { |
59 // Call base class implementation to start preference initialization. | |
60 SettingsDialog.prototype.initializePage.call(this); | |
61 | |
62 $('manage-exceptions-button').onclick = function(event) { | 55 $('manage-exceptions-button').onclick = function(event) { |
63 var page = ManagedUserSettingsExceptionsArea.getInstance(); | |
64 var url = page.name; | |
65 | |
66 OptionsPage.navigateToPage('manualExceptions'); | 56 OptionsPage.navigateToPage('manualExceptions'); |
67 uber.invokeMethodOnParent('setPath', {path: url}); | |
68 uber.invokeMethodOnParent('setTitle', | |
69 {title: loadTimeData.getString('manualExceptionsTabTitle')}); | |
70 }; | 57 }; |
71 | 58 |
72 $('get-content-packs-button').onclick = function(event) { | 59 $('get-content-packs-button').onclick = function(event) { |
73 window.open(loadTimeData.getString('getContentPacksURL')); | 60 window.open(loadTimeData.getString('getContentPacksURL')); |
74 }; | 61 }; |
75 | 62 |
76 if (!cr.isChromeOS) { | 63 if (!cr.isChromeOS) { |
77 $('set-passphrase').onclick = function() { | 64 $('set-passphrase').onclick = function() { |
78 OptionsPage.navigateToPage('setPassphrase'); | 65 OptionsPage.navigateToPage('setPassphrase'); |
79 }; | 66 }; |
80 | 67 |
81 $('use-passphrase-checkbox').onclick = function() { | |
82 $('set-passphrase').disabled = !$('use-passphrase-checkbox').checked; | |
83 }; | |
84 | |
85 var self = this; | 68 var self = this; |
86 $('lock-settings').onclick = function() { | 69 $('lock-settings').onclick = function() { |
87 chrome.send('setElevated', [false]); | 70 chrome.send('setElevated', [false]); |
88 // The managed user is currently authenticated, so don't wait for a | 71 // The managed user is currently authenticated, so don't wait for a |
89 // callback to set the new authentication state since a reset to not | 72 // callback to set the new authentication state since a reset to not |
90 // elevated is done without showing the passphrase dialog. | 73 // elevated is done without showing the passphrase dialog. |
91 self.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED; | 74 self.authenticationState_ = ManagedUserAuthentication.UNAUTHENTICATED; |
92 self.enableControls(false); | 75 self.updateControls_(); |
93 }; | 76 }; |
94 | 77 |
95 $('unlock-settings').onclick = function() { | 78 $('unlock-settings').onclick = function() { |
96 if (self.authenticationState == ManagedUserAuthentication.CHECKING) | 79 if (self.authenticationState_ == ManagedUserAuthentication.CHECKING) |
97 return; | 80 return; |
98 self.authenticationState = ManagedUserAuthentication.CHECKING; | 81 |
| 82 self.authenticationState_ = ManagedUserAuthentication.CHECKING; |
99 chrome.send('setElevated', [true]); | 83 chrome.send('setElevated', [true]); |
100 }; | 84 }; |
101 } | 85 } |
| 86 |
| 87 $('managed-user-settings-done').onclick = function() { |
| 88 OptionsPage.closeOverlay(); |
| 89 }; |
102 }, | 90 }, |
103 | 91 |
104 /** @override */ | 92 /** |
105 handleConfirm: function() { | 93 * Update the page according to the current authentication state. |
106 if (!cr.isChromeOS) { | 94 * @override |
107 if ($('use-passphrase-checkbox').checked && !this.isPassphraseSet) { | 95 */ |
108 OptionsPage.navigateToPage('setPassphrase'); | 96 didShowPage: function() { |
109 return; | 97 this.updateControls_(); |
110 } | 98 chrome.send('settingsPageOpened'); |
111 if (!$('use-passphrase-checkbox').checked) | |
112 chrome.send('resetPassphrase'); | |
113 } | |
114 SettingsDialog.prototype.handleConfirm.call(this); | |
115 }, | 99 }, |
116 | 100 |
117 /** Update the page according to the current authentication state */ | 101 /** |
118 didShowPage: function() { | 102 * Reset the authentication to UNAUTHENTICATED when the managed user |
119 var isAuthenticated = | 103 * settings dialog is closed. |
120 this.authenticationState == ManagedUserAuthentication.AUTHENTICATED; | 104 * @override |
121 this.enableControls(isAuthenticated); | 105 */ |
122 chrome.send('settingsPageOpened'); | 106 didClosePage: function() { |
| 107 // Reset the authentication of the custodian. |
| 108 this.authenticationState_ = ManagedUserAuthentication.UNAUTHENTICATED; |
| 109 chrome.send('setElevated', [false]); |
| 110 chrome.send('confirmManagedUserSettings'); |
123 }, | 111 }, |
124 | 112 |
125 // Enables or disables all controls based on the authentication state of | 113 // Enables or disables all controls based on the authentication state of |
126 // the managed user. If |enable| is true, the controls will be enabled. | 114 // the managed user. If |enable| is true, the controls will be enabled. |
127 enableControls: function(enable) { | 115 updateControls_: function() { |
128 if (!cr.isChromeOS) { | 116 var enable = this.isAuthenticated; |
129 $('set-passphrase').disabled = | 117 |
130 !enable || !$('use-passphrase-checkbox').checked; | 118 $('set-passphrase').disabled = !enable; |
131 $('use-passphrase-checkbox').disabled = !enable; | |
132 } | |
133 // TODO(sergiu): make $('get-content-packs-button') behave the same as | 119 // TODO(sergiu): make $('get-content-packs-button') behave the same as |
134 // the other controls once the button actually does something. | 120 // the other controls once the button actually does something. |
135 $('manage-exceptions-button').disabled = !enable; | 121 $('manage-exceptions-button').disabled = !enable; |
136 $('contentpacks-allow').setDisabled('notManagedUserModifiable', !enable); | 122 $('contentpacks-allow').setDisabled('notManagedUserModifiable', !enable); |
137 $('contentpacks-warn').setDisabled('notManagedUserModifiable', !enable); | 123 $('contentpacks-warn').setDisabled('notManagedUserModifiable', !enable); |
138 $('contentpacks-block').setDisabled('notManagedUserModifiable', !enable); | 124 $('contentpacks-block').setDisabled('notManagedUserModifiable', !enable); |
139 $('safe-search-checkbox').setDisabled('notManagedUserModifiable', | 125 $('safe-search-checkbox').setDisabled('notManagedUserModifiable', |
140 !enable); | 126 !enable); |
141 $('allow-signin-checkbox').setDisabled('notManagedUserModifiable', | 127 |
142 !enable); | |
143 // TODO(akuegel): Add disable-history-deletion-checkbox once this feature | |
144 // is implemented. | |
145 if (enable) | 128 if (enable) |
146 $('managed-user-settings-page').classList.remove('locked'); | 129 $('managed-user-settings-page').classList.remove('locked'); |
147 else | 130 else |
148 $('managed-user-settings-page').classList.add('locked'); | 131 $('managed-user-settings-page').classList.add('locked'); |
149 }, | 132 }, |
150 | 133 |
151 // Is called when the passphrase dialog is closed. |success| is true | 134 // Called when the passphrase dialog is closed. |success| is true iff the |
152 // if the authentication was successful. | 135 // authentication was successful. |
153 isAuthenticated_: function(success) { | 136 setAuthenticated_: function(success) { |
154 if (success) { | 137 if (success) { |
155 this.authenticationState = ManagedUserAuthentication.AUTHENTICATED; | 138 this.authenticationState_ = ManagedUserAuthentication.AUTHENTICATED; |
156 this.enableControls(true); | 139 this.updateControls_(); |
157 } else { | 140 } else { |
158 this.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED; | 141 this.authenticationState_ = ManagedUserAuthentication.UNAUTHENTICATED; |
159 } | 142 } |
160 }, | 143 }, |
161 | 144 |
162 // Reset the authentication to UNAUTHENTICATED when the managed user | |
163 // settings dialog is closed. | |
164 didClosePage: function() { | |
165 // Reset the authentication of the custodian. | |
166 this.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED; | |
167 chrome.send('setElevated', [false]); | |
168 chrome.send('confirmManagedUserSettings'); | |
169 }, | |
170 }; | 145 }; |
171 | 146 |
172 // Sets the authentication state of the managed user. |success| is true if | 147 // Sets the authentication state of the managed user. |success| is true if |
173 // the authentication was successful. | 148 // the authentication was successful. |
174 ManagedUserSettings.isAuthenticated = function(success) { | 149 ManagedUserSettings.setAuthenticated = function(success) { |
175 ManagedUserSettings.getInstance().isAuthenticated_(success); | 150 ManagedUserSettings.getInstance().setAuthenticated_(success); |
176 }; | |
177 | |
178 // Sets the use passphrase checkbox according to if a passphrase is specified | |
179 // or not. |hasPassphrase| is true if the local passphrase is non-empty. | |
180 ManagedUserSettings.passphraseChanged = function(hasPassphrase) { | |
181 var instance = ManagedUserSettings.getInstance(); | |
182 if (instance.authenticationState == ManagedUserAuthentication.AUTHENTICATED) | |
183 $('set-passphrase').disabled = !hasPassphrase; | |
184 $('use-passphrase-checkbox').checked = hasPassphrase; | |
185 ManagedUserSettings.getInstance().isPassphraseSet = hasPassphrase; | |
186 }; | 151 }; |
187 | 152 |
188 var ManagedUserSettingsForTesting = { | 153 var ManagedUserSettingsForTesting = { |
189 getSetPassphraseButton: function() { | 154 getSetPassphraseButton: function() { |
190 return $('set-passphrase'); | 155 return $('set-passphrase'); |
191 }, | 156 }, |
192 getUnlockButton: function() { | 157 getUnlockButton: function() { |
193 return $('unlock-settings'); | 158 return $('unlock-settings'); |
194 } | 159 } |
195 }; | 160 }; |
(...skipping 17 matching lines...) Expand all Loading... |
213 */ | 178 */ |
214 ManagedUserSettings.patternValidityCheckComplete = | 179 ManagedUserSettings.patternValidityCheckComplete = |
215 function(pattern, valid) { | 180 function(pattern, valid) { |
216 $('manual-exceptions').patternValidityCheckComplete(pattern, valid); | 181 $('manual-exceptions').patternValidityCheckComplete(pattern, valid); |
217 }; | 182 }; |
218 | 183 |
219 // Export | 184 // Export |
220 return { | 185 return { |
221 ManagedUserSettings: ManagedUserSettings, | 186 ManagedUserSettings: ManagedUserSettings, |
222 ManagedUserSettingsForTesting: ManagedUserSettingsForTesting, | 187 ManagedUserSettingsForTesting: ManagedUserSettingsForTesting, |
223 ManagedUserAuthentication: ManagedUserAuthentication | |
224 }; | 188 }; |
225 }); | 189 }); |
226 | 190 |
227 } | 191 } |
OLD | NEW |