OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
7 const ArrayDataModel = cr.ui.ArrayDataModel; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
8 | 8 |
9 ///////////////////////////////////////////////////////////////////////////// | 9 ///////////////////////////////////////////////////////////////////////////// |
10 // PasswordManager class: | 10 // PasswordManager class: |
(...skipping 26 matching lines...) Expand all Loading... | |
37 * The password exceptions list. | 37 * The password exceptions list. |
38 * @type {DeletableItemList} | 38 * @type {DeletableItemList} |
39 * @private | 39 * @private |
40 */ | 40 */ |
41 passwordExceptionsList_: null, | 41 passwordExceptionsList_: null, |
42 | 42 |
43 /** @inheritDoc */ | 43 /** @inheritDoc */ |
44 initializePage: function() { | 44 initializePage: function() { |
45 OptionsPage.prototype.initializePage.call(this); | 45 OptionsPage.prototype.initializePage.call(this); |
46 | 46 |
47 $('password-search-box').addEventListener('search', | |
48 this.handleSearchQueryChange_.bind(this)); | |
49 | |
47 this.createSavedPasswordsList_(); | 50 this.createSavedPasswordsList_(); |
48 this.createPasswordExceptionsList_(); | 51 this.createPasswordExceptionsList_(); |
49 }, | 52 }, |
50 | 53 |
51 /** @inheritDoc */ | 54 /** @inheritDoc */ |
52 canShowPage: function() { | 55 canShowPage: function() { |
53 return !PersonalOptions.disablePasswordManagement(); | 56 return !PersonalOptions.disablePasswordManagement(); |
54 }, | 57 }, |
55 | 58 |
56 /** @inheritDoc */ | 59 /** @inheritDoc */ |
(...skipping 17 matching lines...) Expand all Loading... | |
74 * Creates, decorates and initializes the password exceptions list. | 77 * Creates, decorates and initializes the password exceptions list. |
75 * @private | 78 * @private |
76 */ | 79 */ |
77 createPasswordExceptionsList_: function() { | 80 createPasswordExceptionsList_: function() { |
78 this.passwordExceptionsList_ = $('password-exceptions-list'); | 81 this.passwordExceptionsList_ = $('password-exceptions-list'); |
79 options.passwordManager.PasswordExceptionsList.decorate( | 82 options.passwordManager.PasswordExceptionsList.decorate( |
80 this.passwordExceptionsList_); | 83 this.passwordExceptionsList_); |
81 this.passwordExceptionsList_.autoExpands = true; | 84 this.passwordExceptionsList_.autoExpands = true; |
82 }, | 85 }, |
83 | 86 |
87 queryDelayTimerId_: 0, | |
James Hawkins
2011/05/22 00:02:58
nit: Document this variable and move it to the top
Mike Mammarella
2011/05/22 00:35:11
Done. Also documented similar variables in cookie
| |
88 | |
89 /** | |
90 * Handles search query changes. | |
91 * @private | |
James Hawkins
2011/05/22 00:02:58
nit: @private should be last.
Mike Mammarella
2011/05/22 00:35:11
Done.
| |
92 * @param {!Event} e The event object. | |
93 */ | |
94 handleSearchQueryChange_: function(e) { | |
95 if (this.queryDelayTimerId_) | |
96 window.clearTimeout(this.queryDelayTimerId_); | |
97 | |
98 // Searching cookies uses a timeout of 500. We use a shorter timeout | |
James Hawkins
2011/05/22 00:02:58
500ms?
Mike Mammarella
2011/05/22 00:35:11
Done.
| |
99 // because there are probably fewer passwords and we want the UI to be | |
100 // snappier since users (at least I) expect that it's "less work." | |
James Hawkins
2011/05/22 00:02:58
nit: Remove the parenthetical.
Mike Mammarella
2011/05/22 00:35:11
Done.
| |
101 this.queryDelayTimerId_ = window.setTimeout( | |
102 this.searchPasswords_.bind(this), 250); | |
103 }, | |
104 | |
105 lastQuery_: null, | |
106 | |
107 /** | |
108 * Search passwords using text in password-search-box. | |
James Hawkins
2011/05/22 00:02:58
nit: |password-search-box|.
Mike Mammarella
2011/05/22 00:35:11
Done.
| |
109 * @private | |
110 */ | |
111 searchPasswords_: function() { | |
112 this.queryDelayTimerId_ = 0; | |
113 var filter = $('password-search-box').value; | |
114 filter = (filter == '') ? null : filter; | |
115 if (this.lastQuery_ != filter) { | |
116 this.lastQuery_ = filter; | |
117 // Searching for passwords has the side effect of requerying the | |
118 // underlying password store. This is done intentionally, as on OS X and | |
119 // Linux they can change from outside and we won't be notified of it. | |
120 chrome.send('updatePasswordLists'); | |
121 } | |
122 }, | |
123 | |
84 /** | 124 /** |
85 * Updates the visibility of the list and empty list placeholder. | 125 * Updates the visibility of the list and empty list placeholder. |
86 * @param {!List} list The list to toggle visilibility for. | 126 * @param {!List} list The list to toggle visilibility for. |
87 */ | 127 */ |
88 updateListVisibility_: function(list) { | 128 updateListVisibility_: function(list) { |
89 var empty = list.dataModel.length == 0; | 129 var empty = list.dataModel.length == 0; |
90 var listPlaceHolderID = list.id + '-empty-placeholder'; | 130 var listPlaceHolderID = list.id + '-empty-placeholder'; |
91 list.hidden = empty; | 131 list.hidden = empty; |
92 $(listPlaceHolderID).hidden = !empty; | 132 $(listPlaceHolderID).hidden = !empty; |
93 }, | 133 }, |
94 | 134 |
95 /** | 135 /** |
96 * Updates the data model for the saved passwords list with the values from | 136 * Updates the data model for the saved passwords list with the values from |
97 * |entries|. | 137 * |entries|. |
98 * @param {Array} entries The list of saved password data. | 138 * @param {Array} entries The list of saved password data. |
99 */ | 139 */ |
100 setSavedPasswordsList_: function(entries) { | 140 setSavedPasswordsList_: function(entries) { |
141 if (this.lastQuery_) { | |
142 // Implement password searching here in javascript, rather than in C++. | |
143 // The number of saved passwords shouldn't be too big for us to handle. | |
144 var query = this.lastQuery_; | |
145 var filter = function(entry) { | |
146 // Search both URL and username. | |
147 return entry[0].indexOf(query) >= 0 || entry[1].indexOf(query) >= 0; | |
148 }; | |
149 entries = entries.filter(filter); | |
150 } | |
101 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); | 151 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); |
102 this.updateListVisibility_(this.savedPasswordsList_); | 152 this.updateListVisibility_(this.savedPasswordsList_); |
103 }, | 153 }, |
104 | 154 |
105 /** | 155 /** |
106 * Updates the data model for the password exceptions list with the values | 156 * Updates the data model for the password exceptions list with the values |
107 * from |entries|. | 157 * from |entries|. |
108 * @param {Array} entries The list of password exception data. | 158 * @param {Array} entries The list of password exception data. |
109 */ | 159 */ |
110 setPasswordExceptionsList_: function(entries) { | 160 setPasswordExceptionsList_: function(entries) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 PasswordManager.setPasswordExceptionsList = function(entries) { | 202 PasswordManager.setPasswordExceptionsList = function(entries) { |
153 PasswordManager.getInstance().setPasswordExceptionsList_(entries); | 203 PasswordManager.getInstance().setPasswordExceptionsList_(entries); |
154 }; | 204 }; |
155 | 205 |
156 // Export | 206 // Export |
157 return { | 207 return { |
158 PasswordManager: PasswordManager | 208 PasswordManager: PasswordManager |
159 }; | 209 }; |
160 | 210 |
161 }); | 211 }); |
OLD | NEW |