Bug 1394704 draft
authorScott Wu <scottcwwu@gmail.com>
Fri, 01 Sep 2017 18:01:09 +0800
changeset 657368 c49433abc35531dc07309df49d70038bc2c2e314
parent 657025 14eea6bedcf3e2f46ea7c908e1ac9b7d256a42f0
child 729410 45657c3bfb4b229dd0ab97bdaace333d2a1eee60
push id77502
push userbmo:scwwu@mozilla.com
push dateFri, 01 Sep 2017 10:11:16 +0000
bugs1394704
milestone57.0a1
Bug 1394704 MozReview-Commit-ID: LeruZBaVNI5
browser/extensions/formautofill/content/manageDialog.js
--- a/browser/extensions/formautofill/content/manageDialog.js
+++ b/browser/extensions/formautofill/content/manageDialog.js
@@ -24,16 +24,17 @@ this.log = null;
 FormAutofillUtils.defineLazyLogGetter(this, "manageAddresses");
 
 class ManageRecords {
   constructor(subStorageName, elements) {
     this._storageInitPromise = profileStorage.initialize();
     this._subStorageName = subStorageName;
     this._elements = elements;
     this._records = [];
+    this._timeStamp = 0;
     this.prefWin = window.opener;
     this.localizeDocument();
     window.addEventListener("DOMContentLoaded", this, {once: true});
   }
 
   async init() {
     await this.loadRecords();
     this.attachEventListeners();
@@ -70,35 +71,43 @@ class ManageRecords {
   }
 
   /**
    * Load records and render them.
    */
   async loadRecords() {
     let storage = await this.getStorage();
     let records = storage.getAll();
+    let timeStamp = new Date().getTime();
+    this._timeStamp = timeStamp;
+    for (let record of records) {
+      record.label = await this.getLabel(record);
+    }
+    if (this._timeStamp > timeStamp) {
+      return;
+    }
     // Sort by last modified time starting with most recent
     records.sort((a, b) => b.timeLastModified - a.timeLastModified);
-    await this.renderRecordElements(records);
+    this.renderRecordElements(records);
     this.updateButtonsStates(this._selectedOptions.length);
     // For testing only: Notify when records are loaded
     this._elements.records.dispatchEvent(new CustomEvent("RecordsLoaded"));
   }
 
   /**
    * Render the records onto the page while maintaining selected options if
    * they still exist.
    *
    * @param  {array<object>} records
    */
-  async renderRecordElements(records) {
+  renderRecordElements(records) {
     let selectedGuids = this._selectedOptions.map(option => option.value);
     this.clearRecordElements();
     for (let record of records) {
-      let option = new Option(await this.getLabel(record),
+      let option = new Option(record.label,
                               record.guid,
                               false,
                               selectedGuids.includes(record.guid));
       option.record = record;
       this._elements.records.appendChild(option);
     }
   }