| 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var Page = cr.ui.pageManager.Page; | 6 /** @const */ var Page = cr.ui.pageManager.Page; |
| 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; | 7 /** @const */ var PageManager = cr.ui.pageManager.PageManager; |
| 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 9 | 9 |
| 10 ///////////////////////////////////////////////////////////////////////////// | 10 ///////////////////////////////////////////////////////////////////////////// |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if (this.lastQuery_ != filter) { | 153 if (this.lastQuery_ != filter) { |
| 154 this.lastQuery_ = filter; | 154 this.lastQuery_ = filter; |
| 155 // Searching for passwords has the side effect of requerying the | 155 // Searching for passwords has the side effect of requerying the |
| 156 // underlying password store. This is done intentionally, as on OS X and | 156 // underlying password store. This is done intentionally, as on OS X and |
| 157 // Linux they can change from outside and we won't be notified of it. | 157 // Linux they can change from outside and we won't be notified of it. |
| 158 chrome.send('updatePasswordLists'); | 158 chrome.send('updatePasswordLists'); |
| 159 } | 159 } |
| 160 }, | 160 }, |
| 161 | 161 |
| 162 /** | 162 /** |
| 163 * Updates the visibility of the list and empty list placeholder. | 163 * Updates the list with the given entries and updates the visibility of the |
| 164 * list and empty list placeholder. |
| 164 * @param {!cr.ui.List} list The list to toggle visilibility for. | 165 * @param {!cr.ui.List} list The list to toggle visilibility for. |
| 166 * @param {!Array} entries The list of entries. |
| 165 */ | 167 */ |
| 166 updateListVisibility_: function(list) { | 168 updateListAndVisibility_: function(list, entries) { |
| 167 var empty = list.dataModel.length == 0; | 169 // Setting the dataModel results in a redraw of the viewport, which is why |
| 170 // the visibility needs to be updated first. Otherwise, redraw will not |
| 171 // render the updated entries when transitioning from a previously empty |
| 172 // list to a non-empty one. The attribute list.hidden would be true in |
| 173 // this case, resulting in |redraw()| not adding the new elements to the |
| 174 // viewport and thus showing a empty list to the user |
| 175 // (http://crbug.com/672869). |
| 176 var empty = entries.length == 0; |
| 168 var listPlaceHolderID = list.id + '-empty-placeholder'; | 177 var listPlaceHolderID = list.id + '-empty-placeholder'; |
| 169 list.hidden = empty; | 178 list.hidden = empty; |
| 170 $(listPlaceHolderID).hidden = !empty; | 179 $(listPlaceHolderID).hidden = !empty; |
| 180 list.dataModel = new ArrayDataModel(entries); |
| 171 }, | 181 }, |
| 172 | 182 |
| 173 /** | 183 /** |
| 174 * Updates the data model for the saved passwords list with the values from | 184 * Updates the data model for the saved passwords list with the values from |
| 175 * |entries|. | 185 * |entries|. |
| 176 * @param {!Array} entries The list of saved password data. | 186 * @param {!Array} entries The list of saved password data. |
| 177 */ | 187 */ |
| 178 setSavedPasswordsList_: function(entries) { | 188 setSavedPasswordsList_: function(entries) { |
| 179 if (this.lastQuery_) { | 189 if (this.lastQuery_) { |
| 180 // Implement password searching here in javascript, rather than in C++. | 190 // Implement password searching here in javascript, rather than in C++. |
| 181 // The number of saved passwords shouldn't be too big for us to handle. | 191 // The number of saved passwords shouldn't be too big for us to handle. |
| 182 var query = this.lastQuery_; | 192 var query = this.lastQuery_; |
| 183 var filter = function(entry, index, list) { | 193 var filter = function(entry, index, list) { |
| 184 // Search both shown URL and username. | 194 // Search both shown URL and username. |
| 185 var shownOrigin = entry[options.passwordManager.SHOWN_ORIGIN_FIELD]; | 195 var shownOrigin = entry[options.passwordManager.SHOWN_ORIGIN_FIELD]; |
| 186 var username = entry[options.passwordManager.USERNAME_FIELD]; | 196 var username = entry[options.passwordManager.USERNAME_FIELD]; |
| 187 if (shownOrigin.toLowerCase().indexOf(query.toLowerCase()) >= 0 || | 197 if (shownOrigin.toLowerCase().indexOf(query.toLowerCase()) >= 0 || |
| 188 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { | 198 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { |
| 189 // Keep the original index so we can delete correctly. See also | 199 // Keep the original index so we can delete correctly. See also |
| 190 // deleteItemAtIndex() in password_manager_list.js that uses this. | 200 // deleteItemAtIndex() in password_manager_list.js that uses this. |
| 191 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; | 201 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; |
| 192 return true; | 202 return true; |
| 193 } | 203 } |
| 194 return false; | 204 return false; |
| 195 }; | 205 }; |
| 196 entries = entries.filter(filter); | 206 entries = entries.filter(filter); |
| 197 } | 207 } |
| 198 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); | 208 this.updateListAndVisibility_(assert(this.savedPasswordsList_), entries); |
| 199 this.updateListVisibility_(this.savedPasswordsList_); | |
| 200 }, | 209 }, |
| 201 | 210 |
| 202 /** | 211 /** |
| 203 * Updates the data model for the password exceptions list with the values | 212 * Updates the data model for the password exceptions list with the values |
| 204 * from |entries|. | 213 * from |entries|. |
| 205 * @param {!Array} entries The list of password exception data. | 214 * @param {!Array} entries The list of password exception data. |
| 206 */ | 215 */ |
| 207 setPasswordExceptionsList_: function(entries) { | 216 setPasswordExceptionsList_: function(entries) { |
| 208 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); | 217 this.updateListAndVisibility_( |
| 209 this.updateListVisibility_(this.passwordExceptionsList_); | 218 assert(this.passwordExceptionsList_), entries); |
| 210 }, | 219 }, |
| 211 | 220 |
| 212 /** | 221 /** |
| 213 * Reveals the password for a saved password entry. This is called by the | 222 * Reveals the password for a saved password entry. This is called by the |
| 214 * backend after it has authenticated the user. | 223 * backend after it has authenticated the user. |
| 215 * @param {number} index The original index of the entry in the model. | 224 * @param {number} index The original index of the entry in the model. |
| 216 * @param {string} password The saved password. | 225 * @param {string} password The saved password. |
| 217 */ | 226 */ |
| 218 showPassword_: function(index, password) { | 227 showPassword_: function(index, password) { |
| 219 var model = this.savedPasswordsList_.dataModel; | 228 var model = this.savedPasswordsList_.dataModel; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 'showImportExportButton', | 287 'showImportExportButton', |
| 279 'showPassword', | 288 'showPassword', |
| 280 ]); | 289 ]); |
| 281 | 290 |
| 282 // Export | 291 // Export |
| 283 return { | 292 return { |
| 284 PasswordManager: PasswordManager | 293 PasswordManager: PasswordManager |
| 285 }; | 294 }; |
| 286 | 295 |
| 287 }); | 296 }); |
| OLD | NEW |