Bug 1360374 - Identify FormAutofill fields when a field is focused on.; r?MattN
MozReview-Commit-ID: 3VtrwptASnr
--- a/browser/extensions/formautofill/FormAutofillContent.jsm
+++ b/browser/extensions/formautofill/FormAutofillContent.jsm
@@ -405,16 +405,23 @@ var FormAutofillContent = {
// Collects root forms from inputs.
for (let field of doc.getElementsByTagName("input")) {
// We only consider text-like fields for now until we support radio and
// checkbox buttons in the future.
if (!field.mozIsTextField(true)) {
continue;
}
+ // For now skip consider fields in forms we've already seen before even
+ // if the specific field wasn't seen before. Ideally whether the field is
+ // already in the handler's form details would be considered.
+ if (this.getFormHandler(field)) {
+ continue;
+ }
+
let formLike = FormLikeFactory.createFromField(field);
if (!forms.some(form => form.rootElement === formLike.rootElement)) {
forms.push(formLike);
}
}
this.log.debug("Found", forms.length, "forms");
--- a/browser/extensions/formautofill/content/FormAutofillFrameScript.js
+++ b/browser/extensions/formautofill/content/FormAutofillFrameScript.js
@@ -18,37 +18,37 @@ Cu.import("resource://formautofill/FormA
/**
* Handles content's interactions for the frame.
*
* NOTE: Declares it by "var" to make it accessible in unit tests.
*/
var FormAutofillFrameScript = {
init() {
- addEventListener("DOMContentLoaded", this);
+ addEventListener("focusin", this);
addMessageListener("FormAutofill:PreviewProfile", this);
addMessageListener("FormAutoComplete:PopupClosed", this);
},
handleEvent(evt) {
if (!evt.isTrusted) {
return;
}
if (!Services.prefs.getBoolPref("browser.formautofill.enabled")) {
return;
}
switch (evt.type) {
- case "DOMContentLoaded": {
- let doc = evt.target;
- if (!(doc instanceof Ci.nsIDOMHTMLDocument)) {
+ case "focusin": {
+ let element = evt.target;
+ if (!(element instanceof Ci.nsIDOMHTMLInputElement)) {
return;
}
- FormAutofillContent.identifyAutofillFields(doc);
+ FormAutofillContent.identifyAutofillFields(element.ownerDocument);
break;
}
}
},
receiveMessage(message) {
if (!Services.prefs.getBoolPref("browser.formautofill.enabled")) {
return;