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; | 9 /** @const */ var SettingsDialog = options.SettingsDialog; |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
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 var Authentication = { | |
Bernhard Bauer
2013/02/20 13:06:20
I think we should prefix this with ManagedUser?
Adrian Kuegel
2013/02/20 13:28:26
Done.
| |
32 // The manager of the managed account is not authenticated. | |
33 UNAUTHENTICATED: 'unauthenticated', | |
34 | |
35 // The authentication is currently being checked. | |
36 CHECKING: 'checking', | |
37 | |
38 // The manager of the managed account is authenticated. | |
39 AUTHENTICATED: 'authenticated' | |
40 }; | |
41 | |
31 ManagedUserSettings.prototype = { | 42 ManagedUserSettings.prototype = { |
32 // Inherit from SettingsDialog. | 43 // Inherit from SettingsDialog. |
33 __proto__: SettingsDialog.prototype, | 44 __proto__: SettingsDialog.prototype, |
34 | 45 |
46 // The current authentication state of the manager of the managed account. | |
47 authenticationState: Authentication.UNAUTHENTICATED, | |
48 | |
49 // Stores if the local passphrase of the manager of the managed account is | |
50 // set. If it is not set, no authentication is required. | |
51 isPassphraseSet: false, | |
52 | |
35 /** | 53 /** |
36 * Initialize the page. | 54 * Initialize the page. |
37 * @override | 55 * @override |
38 */ | 56 */ |
39 initializePage: function() { | 57 initializePage: function() { |
40 // Call base class implementation to start preference initialization. | 58 // Call base class implementation to start preference initialization. |
41 SettingsDialog.prototype.initializePage.call(this); | 59 SettingsDialog.prototype.initializePage.call(this); |
60 var self = 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 $('unlock-settings').onclick = function() { | |
75 if (self.authenticationState == Authentication.CHECKING) | |
76 return; | |
77 chrome.send('displayPassphraseDialog', | |
78 ['options.ManagedUserSettings.isAuthenticated']); | |
79 self.authenticationState = Authentication.CHECKING; | |
80 }; | |
51 }, | 81 }, |
52 /** @override */ | 82 /** @override */ |
53 handleConfirm: function() { | 83 handleConfirm: function() { |
84 if ($('use-passphrase-checkbox').checked && !this.isPassphraseSet) { | |
85 OptionsPage.navigateToPage('setPassphrase'); | |
86 return; | |
87 } | |
88 if (!$('use-passphrase-checkbox').checked) | |
89 chrome.send('resetPassphrase'); | |
54 chrome.send('confirmManagedUserSettings'); | 90 chrome.send('confirmManagedUserSettings'); |
55 SettingsDialog.prototype.handleConfirm.call(this); | 91 SettingsDialog.prototype.handleConfirm.call(this); |
56 }, | 92 }, |
93 enableControls: function(enable) { | |
94 $('set-passphrase').disabled = !enable; | |
95 $('get-content-packs-button').disabled = !enable; | |
96 $('contentpacks-allow').setDisabled('notManagedUserModifiable', !enable); | |
97 $('contentpacks-warn').setDisabled('notManagedUserModifiable', !enable); | |
98 $('contentpacks-block').setDisabled('notManagedUserModifiable', !enable); | |
99 $('safe-search-checkbox').setDisabled( | |
100 'notManagedUserModifiable', !enable); | |
101 // TODO(akuegel): Add disable-signin-checkbox and | |
102 // disable-history-deletion-checkbox once these features are implemented | |
103 $('use-passphrase-checkbox').disabled = !enable; | |
104 $('unlock-settings').disabled = enable; | |
105 }, | |
106 isAuthenticated_: function(success) { | |
107 if (success) { | |
108 this.authenticationState = Authentication.AUTHENTICATED; | |
109 this.enableControls(true); | |
110 } else { | |
111 this.authenticationState = Authentication.UNAUTHENTICATED; | |
112 } | |
113 }, | |
114 didClosePage: function() { | |
115 // Reset the authentication of the custodian. | |
116 this.authenticationState = Authentication.UNAUTHENTICATED; | |
117 chrome.send('endAuthentication'); | |
118 }, | |
119 }; | |
120 | |
121 ManagedUserSettings.initializeSetPassphraseButton = function(hasPassphrase) { | |
122 $('set-passphrase').disabled = !hasPassphrase; | |
123 $('use-passphrase-checkbox').checked = hasPassphrase; | |
124 var instance = ManagedUserSettings.getInstance(); | |
125 instance.isPassphraseSet = hasPassphrase; | |
126 if (hasPassphrase) { | |
127 instance.authenticationState = Authentication.UNAUTHENTICATED; | |
128 instance.enableControls(false); | |
129 } else { | |
130 instance.authenticationState = Authentication.AUTHENTICATED; | |
131 $('unlock-settings').disabled = true; | |
132 } | |
133 }; | |
134 | |
135 ManagedUserSettings.isAuthenticated = function(success) { | |
136 ManagedUserSettings.getInstance().isAuthenticated_(success); | |
137 }; | |
138 | |
139 ManagedUserSettings.passphraseChanged = function(isPassphraseSet) { | |
140 ManagedUserSettings.getInstance().isPassphraseSet = isPassphraseSet; | |
57 }; | 141 }; |
58 | 142 |
59 var ManagedUserSettingsForTesting = { | 143 var ManagedUserSettingsForTesting = { |
60 getSetPassphraseButton: function() { | 144 getSetPassphraseButton: function() { |
61 return $('set-passphrase'); | 145 return $('set-passphrase'); |
146 }, | |
147 getUnlockButton: function() { | |
148 return $('unlock-settings'); | |
62 } | 149 } |
63 }; | 150 }; |
64 | 151 |
65 // Export | 152 // Export |
66 return { | 153 return { |
67 ManagedUserSettings: ManagedUserSettings, | 154 ManagedUserSettings: ManagedUserSettings, |
68 ManagedUserSettingsForTesting: ManagedUserSettingsForTesting | 155 ManagedUserSettingsForTesting: ManagedUserSettingsForTesting, |
156 Authentication: Authentication | |
69 }; | 157 }; |
70 }); | 158 }); |
71 | 159 |
72 } | 160 } |
OLD | NEW |