OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var OptionsPage = options.OptionsPage; | 6 /** @const */ var OptionsPage = options.OptionsPage; |
7 | 7 |
8 ////////////////////////////////////////////////////////////////////////////// | 8 ////////////////////////////////////////////////////////////////////////////// |
9 // ManagedUserSetPassphraseOverlay class: | 9 // ManagedUserSetPassphraseOverlay class: |
10 | 10 |
11 /** | 11 /** |
12 * Encapsulated handling of the Managed User Set Passphrase page. | 12 * Encapsulated handling of the Managed User Set Passphrase page. |
13 * @constructor | 13 * @constructor |
14 */ | 14 */ |
15 function ManagedUserSetPassphraseOverlay() { | 15 function ManagedUserSetPassphraseOverlay() { |
16 OptionsPage.call( | 16 OptionsPage.call( |
17 this, | 17 this, |
18 'setPassphrase', | 18 'setPassphrase', |
19 loadTimeData.getString('setPassphraseTitle'), | 19 loadTimeData.getString('setPassphraseTitle'), |
20 'managed-user-set-passphrase-overlay'); | 20 'managed-user-set-passphrase-overlay'); |
21 } | 21 } |
22 | 22 |
23 cr.addSingletonGetter(ManagedUserSetPassphraseOverlay); | 23 cr.addSingletonGetter(ManagedUserSetPassphraseOverlay); |
24 | 24 |
25 /** Closes the page and resets the passphrase fields */ | |
26 var closePage = function(container) { | |
27 // Reseting the fields directly would lead to a flicker, so listen to | |
28 // webkitTransitionEnd to clear them after that. Similar to how it is done | |
29 // in setOverlayVisible_ in options_page.js. | |
30 container.addEventListener('webkitTransitionEnd', function f(e) { | |
31 if (e.target != e.currentTarget || e.propertyName != 'opacity') | |
32 return; | |
33 container.removeEventListener('webkitTransitionEnd', f); | |
34 | |
35 // Reset the fields. | |
36 $('managed-user-passphrase').value = ''; | |
37 $('passphrase-confirm').value = ''; | |
38 $('passphrase-mismatch').hidden = true; | |
39 }); | |
40 OptionsPage.closeOverlay(); | |
41 }; | |
42 | |
43 ManagedUserSetPassphraseOverlay.prototype = { | 25 ManagedUserSetPassphraseOverlay.prototype = { |
44 __proto__: OptionsPage.prototype, | 26 __proto__: OptionsPage.prototype, |
45 | 27 |
46 /** @override */ | 28 /** @override */ |
47 initializePage: function() { | 29 initializePage: function() { |
48 OptionsPage.prototype.initializePage.call(this); | 30 OptionsPage.prototype.initializePage.call(this); |
49 $('managed-user-passphrase').oninput = this.updateDisplay_; | 31 $('managed-user-passphrase').oninput = this.updateDisplay_; |
50 $('passphrase-confirm').oninput = this.updateDisplay_; | 32 $('passphrase-confirm').oninput = this.updateDisplay_; |
51 | 33 |
52 $('save-passphrase').onclick = this.setPassphrase_.bind(this); | 34 $('save-passphrase').onclick = this.setPassphrase_.bind(this); |
(...skipping 11 matching lines...) Expand all Loading... |
64 if (!$('passphrase-confirm').validity.valid || | 46 if (!$('passphrase-confirm').validity.valid || |
65 !$('managed-user-passphrase').validity.valid) { | 47 !$('managed-user-passphrase').validity.valid) { |
66 return; | 48 return; |
67 } | 49 } |
68 // Check if the user pressed enter. | 50 // Check if the user pressed enter. |
69 if (event.keyCode == 13) | 51 if (event.keyCode == 13) |
70 self.setPassphrase_(event); | 52 self.setPassphrase_(event); |
71 }; | 53 }; |
72 | 54 |
73 $('cancel-passphrase').onclick = function(event) { | 55 $('cancel-passphrase').onclick = function(event) { |
74 closePage(self.container); | 56 self.closePage(); |
75 }; | 57 }; |
76 }, | 58 }, |
77 | 59 |
78 /** Updates the display according to the validity of the user input. */ | 60 /** Updates the display according to the validity of the user input. */ |
79 updateDisplay_: function() { | 61 updateDisplay_: function() { |
80 var valid = | 62 var valid = |
81 $('passphrase-confirm').value == $('managed-user-passphrase').value; | 63 $('passphrase-confirm').value == $('managed-user-passphrase').value; |
82 $('passphrase-mismatch').hidden = valid; | 64 $('passphrase-mismatch').hidden = valid; |
83 $('passphrase-confirm').setCustomValidity( | 65 $('passphrase-confirm').setCustomValidity( |
84 valid ? '' : $('passphrase-mismatch').textContent); | 66 valid ? '' : $('passphrase-mismatch').textContent); |
85 $('save-passphrase').disabled = | 67 $('save-passphrase').disabled = |
86 !$('passphrase-confirm').validity.valid || | 68 !$('passphrase-confirm').validity.valid || |
87 !$('managed-user-passphrase').validity.valid; | 69 !$('managed-user-passphrase').validity.valid; |
88 }, | 70 }, |
89 /** | 71 /** |
90 * Sets the passphrase and closes the overlay. | 72 * Sets the passphrase and closes the overlay. |
91 * @param {Event} event The event that triggered the call to this function. | 73 * @param {Event} event The event that triggered the call to this function. |
92 */ | 74 */ |
93 setPassphrase_: function(event) { | 75 setPassphrase_: function(event) { |
94 chrome.send('setPassphrase', [$('managed-user-passphrase').value]); | 76 chrome.send('setPassphrase', [$('managed-user-passphrase').value]); |
95 closePage(this.container); | 77 this.closePage(); |
96 }, | 78 }, |
97 | 79 |
98 /** @override */ | 80 /** @override */ |
99 canShowPage: function() { | 81 canShowPage: function() { |
100 return ManagedUserSettings.getInstance().authenticationState == | 82 return ManagedUserSettings.getInstance().authenticationState == |
101 options.ManagedUserAuthentication.AUTHENTICATED; | 83 options.ManagedUserAuthentication.AUTHENTICATED; |
102 }, | 84 }, |
103 | 85 |
104 /** @override */ | 86 /** @override */ |
105 didShowPage: function() { | 87 didShowPage: function() { |
106 $('managed-user-passphrase').focus(); | 88 $('managed-user-passphrase').focus(); |
107 }, | 89 }, |
108 | 90 |
109 /** | 91 /** |
110 * Make sure that we reset the fields on cancel. | 92 * Make sure that we reset the fields on cancel. |
111 */ | 93 */ |
112 handleCancel: function() { | 94 handleCancel: function() { |
113 closePage(this.container); | 95 this.closePage(); |
| 96 }, |
| 97 |
| 98 /** Closes the page and resets the passphrase fields */ |
| 99 closePage: function() { |
| 100 // Reseting the fields directly would lead to a flicker, so listen to |
| 101 // webkitTransitionEnd to clear them after that. Similar to how it is done |
| 102 // in setOverlayVisible_ in options_page.js. |
| 103 var self = this; |
| 104 this.container.addEventListener('webkitTransitionEnd', function f(e) { |
| 105 if (e.target != e.currentTarget || e.propertyName != 'opacity') |
| 106 return; |
| 107 self.container.removeEventListener('webkitTransitionEnd', f); |
| 108 |
| 109 // Reset the fields. |
| 110 $('managed-user-passphrase').value = ''; |
| 111 $('passphrase-confirm').value = ''; |
| 112 self.updateDisplay_(); |
| 113 }); |
| 114 OptionsPage.closeOverlay(); |
114 } | 115 } |
115 }; | 116 }; |
116 | 117 |
117 /** Used for browsertests. */ | 118 /** Used for browsertests. */ |
118 var ManagedUserSetPassphraseForTesting = { | 119 var ManagedUserSetPassphraseForTesting = { |
119 getPassphraseInput: function() { | 120 getPassphraseInput: function() { |
120 return $('managed-user-passphrase'); | 121 return $('managed-user-passphrase'); |
121 }, | 122 }, |
122 getPassphraseConfirmInput: function() { | 123 getPassphraseConfirmInput: function() { |
123 return $('passphrase-confirm'); | 124 return $('passphrase-confirm'); |
124 }, | 125 }, |
125 getSavePassphraseButton: function() { | 126 getSavePassphraseButton: function() { |
126 return $('save-passphrase'); | 127 return $('save-passphrase'); |
127 }, | 128 }, |
128 updateDisplay: function() { | 129 updateDisplay: function() { |
129 return ManagedUserSetPassphraseOverlay.getInstance().updateDisplay_(); | 130 return ManagedUserSetPassphraseOverlay.getInstance().updateDisplay_(); |
130 } | 131 } |
131 }; | 132 }; |
132 | 133 |
133 // Export | 134 // Export |
134 return { | 135 return { |
135 ManagedUserSetPassphraseOverlay: ManagedUserSetPassphraseOverlay, | 136 ManagedUserSetPassphraseOverlay: ManagedUserSetPassphraseOverlay, |
136 ManagedUserSetPassphraseForTesting: ManagedUserSetPassphraseForTesting | 137 ManagedUserSetPassphraseForTesting: ManagedUserSetPassphraseForTesting |
137 }; | 138 }; |
138 | 139 |
139 }); | 140 }); |
OLD | NEW |