Bug 1338420 - Part 1: Cache profiles in initialProcess and check while identifying fields
MozReview-Commit-ID: HW6ToWQlOe2
--- 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);