Bug 1338420 - Part 1: Cache profiles in initialProcess and check while identifying fields draft
authorsteveck-chung <schung@mozilla.com>
Thu, 23 Feb 2017 17:09:14 +0800
changeset 488572 955415cc781e6dd4ef2076f111f3fc36a9521757
parent 488302 32dcdde1fc64fc39a9065dc4218265dbc727673f
child 491828 52feb48a25747997f73126b3133522085ba801d0
push id46581
push userbmo:schung@mozilla.com
push dateThu, 23 Feb 2017 10:46:25 +0000
bugs1338420
milestone54.0a1
Bug 1338420 - Part 1: Cache profiles in initialProcess and check while identifying fields MozReview-Commit-ID: HW6ToWQlOe2
browser/extensions/formautofill/FormAutofillContent.jsm
browser/extensions/formautofill/FormAutofillParent.jsm
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -343,17 +343,27 @@ var FormAutofillContent = {
       if (formHandler.fieldDetails.length < AUTOFILL_FIELDS_THRESHOLD) {
         this.log.debug("Ignoring form since it has only", formHandler.fieldDetails.length,
                        "field(s)");
         return;
       }
 
       this._formsDetails.set(form.rootElement, formHandler);
       this.log.debug("Adding form handler to _formsDetails:", formHandler);
-      formHandler.fieldDetails.forEach(detail => this._markAsAutofillField(detail.element));
+      formHandler.fieldDetails.forEach(detail => {
+        if (this._fieldInProfile(detail.fieldName)) {
+          this._markAsAutofillField(detail.element);
+        }
+      });
+    });
+  },
+
+  _fieldInProfile(fieldName) {
+    return Services.cpmm.initialProcessData.profiles.some((profile) => {
+      return !!profile[fieldName]
     });
   },
 
   _markAsAutofillField(field) {
     formFillController.markAsAutofillField(field);
   },
 };
 
--- a/browser/extensions/formautofill/FormAutofillParent.jsm
+++ b/browser/extensions/formautofill/FormAutofillParent.jsm
@@ -79,16 +79,17 @@ FormAutofillParent.prototype = {
 
     // Observing the pref and storage changes
     Services.prefs.addObserver(ENABLED_PREF, this, false);
     Services.obs.addObserver(this, "formautofill-storage-changed", false);
 
     // Force to trigger the onStatusChanged function for setting listeners properly
     // while initizlization
     this._setStatus(this._getStatus());
+    Services.ppmm.initialProcessData.profiles = this._profileStore.getAll();
   },
 
   observe(subject, topic, data) {
     log.debug("observe:", topic, "with data:", data);
     switch (topic) {
       case "advanced-pane-loaded": {
         let formAutofillPreferences = new FormAutofillPreferences();
         let document = subject.document;
@@ -104,16 +105,18 @@ FormAutofillParent.prototype = {
         let currentStatus = this._getStatus();
         if (currentStatus !== this._enabled) {
           this._setStatus(currentStatus);
         }
         break;
       }
 
       case "formautofill-storage-changed": {
+        Services.ppmm.initialProcessData.profiles = this._profileStore.getAll();
+
         // Early exit if the action is not "add" nor "remove"
         if (data != "add" && data != "remove") {
           break;
         }
 
         let currentStatus = this._getStatus();
         if (currentStatus !== this._enabled) {
           this._setStatus(currentStatus);