Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: chrome/browser/resources/options/password_manager.js

Issue 2571443002: Fix bug when transitioning from an empty to a non-empty password list (Closed)
Patch Set: Updated comment for clarity Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 eliding of origins. If there is no enough space to show the full 184 * Updates eliding of origins. If there is no enough space to show the full
175 * origin, the origin is elided from the left with ellipsis. 185 * origin, the origin is elided from the left with ellipsis.
176 * @param {!cr.ui.List} list The list to update eliding. 186 * @param {!cr.ui.List} list The list to update eliding.
177 */ 187 */
178 updateOriginsEliding_: function(list) { 188 updateOriginsEliding_: function(list) {
179 var entries = list.getElementsByClassName('deletable-item'); 189 var entries = list.getElementsByClassName('deletable-item');
180 if (entries.length == 0) 190 if (entries.length == 0)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) { 248 username.toLowerCase().indexOf(query.toLowerCase()) >= 0) {
239 // Keep the original index so we can delete correctly. See also 249 // Keep the original index so we can delete correctly. See also
240 // deleteItemAtIndex() in password_manager_list.js that uses this. 250 // deleteItemAtIndex() in password_manager_list.js that uses this.
241 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index; 251 entry[options.passwordManager.ORIGINAL_INDEX_FIELD] = index;
242 return true; 252 return true;
243 } 253 }
244 return false; 254 return false;
245 }; 255 };
246 entries = entries.filter(filter); 256 entries = entries.filter(filter);
247 } 257 }
248 this.savedPasswordsList_.dataModel = new ArrayDataModel(entries); 258 assert(this.savedPasswordsList_ !== null);
249 this.updateListVisibility_(this.savedPasswordsList_); 259 this.updateListAndVisibility_(this.savedPasswordsList_, entries);
Dan Beam 2016/12/20 22:25:12 can you just wrap with assert(), as in: this.upda
jdoerrie 2016/12/21 07:07:41 Done.
250 // updateOriginsEliding_ should be called after updateListVisibility_, 260 // updateOriginsEliding_ should be called after updateListVisibility_,
251 // otherwise updateOrigins... might be not able to read width of elements. 261 // otherwise updateOrigins... might be not able to read width of elements.
252 this.updateOriginsEliding_(this.savedPasswordsList_); 262 this.updateOriginsEliding_(this.savedPasswordsList_);
253 }, 263 },
254 264
255 /** 265 /**
256 * Updates the data model for the password exceptions list with the values 266 * Updates the data model for the password exceptions list with the values
257 * from |entries|. 267 * from |entries|.
258 * @param {!Array} entries The list of password exception data. 268 * @param {!Array} entries The list of password exception data.
259 */ 269 */
260 setPasswordExceptionsList_: function(entries) { 270 setPasswordExceptionsList_: function(entries) {
261 this.passwordExceptionsList_.dataModel = new ArrayDataModel(entries); 271 assert(this.passwordExceptionsList_ !== null);
262 this.updateListVisibility_(this.passwordExceptionsList_); 272 this.updateListAndVisibility_(this.passwordExceptionsList_, entries);
263 // updateOriginsEliding_ should be called after updateListVisibility_, 273 // updateOriginsEliding_ should be called after updateListVisibility_,
264 // otherwise updateOrigins... might be not able to read width of elements. 274 // otherwise updateOrigins... might be not able to read width of elements.
265 this.updateOriginsEliding_(this.passwordExceptionsList_); 275 this.updateOriginsEliding_(this.passwordExceptionsList_);
266 }, 276 },
267 277
268 /** 278 /**
269 * Reveals the password for a saved password entry. This is called by the 279 * Reveals the password for a saved password entry. This is called by the
270 * backend after it has authenticated the user. 280 * backend after it has authenticated the user.
271 * @param {number} index The original index of the entry in the model. 281 * @param {number} index The original index of the entry in the model.
272 * @param {string} password The saved password. 282 * @param {string} password The saved password.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 'showImportExportButton', 344 'showImportExportButton',
335 'showPassword', 345 'showPassword',
336 ]); 346 ]);
337 347
338 // Export 348 // Export
339 return { 349 return {
340 PasswordManager: PasswordManager 350 PasswordManager: PasswordManager
341 }; 351 };
342 352
343 }); 353 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698