зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1349489 - Part 1: Move the codes from FormAutofillHandler.collectFormFields to FormAutofillHeuristics.getFormInfo.; r=MattN
MozReview-Commit-ID: BQTpopSyBUe --HG-- extra : rebase_source : 0f7494d1c2e1e991d8a0a45a0bbeed356feee457
This commit is contained in:
Родитель
6125817003
Коммит
71cb736348
|
@ -61,36 +61,8 @@ FormAutofillHandler.prototype = {
|
|||
* Set fieldDetails from the form about fields that can be autofilled.
|
||||
*/
|
||||
collectFormFields() {
|
||||
this.fieldDetails = [];
|
||||
|
||||
for (let element of this.form.elements) {
|
||||
// Exclude elements to which no autocomplete field has been assigned.
|
||||
let info = FormAutofillHeuristics.getInfo(element);
|
||||
if (!info) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Store the association between the field metadata and the element.
|
||||
if (this.fieldDetails.some(f => f.section == info.section &&
|
||||
f.addressType == info.addressType &&
|
||||
f.contactType == info.contactType &&
|
||||
f.fieldName == info.fieldName)) {
|
||||
// A field with the same identifier already exists.
|
||||
log.debug("Not collecting a field matching another with the same info:", info);
|
||||
continue;
|
||||
}
|
||||
|
||||
let formatWithElement = {
|
||||
section: info.section,
|
||||
addressType: info.addressType,
|
||||
contactType: info.contactType,
|
||||
fieldName: info.fieldName,
|
||||
elementWeakRef: Cu.getWeakReference(element),
|
||||
};
|
||||
|
||||
this.fieldDetails.push(formatWithElement);
|
||||
}
|
||||
|
||||
let fieldDetails = FormAutofillHeuristics.getFormInfo(this.form);
|
||||
this.fieldDetails = fieldDetails ? fieldDetails : [];
|
||||
log.debug("Collected details on", this.fieldDetails.length, "fields");
|
||||
},
|
||||
|
||||
|
|
|
@ -34,6 +34,39 @@ this.FormAutofillHeuristics = {
|
|||
"email",
|
||||
],
|
||||
|
||||
getFormInfo(form) {
|
||||
let fieldDetails = [];
|
||||
for (let element of form.elements) {
|
||||
// Exclude elements to which no autocomplete field has been assigned.
|
||||
let info = this.getInfo(element);
|
||||
if (!info) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Store the association between the field metadata and the element.
|
||||
if (fieldDetails.some(f => f.section == info.section &&
|
||||
f.addressType == info.addressType &&
|
||||
f.contactType == info.contactType &&
|
||||
f.fieldName == info.fieldName)) {
|
||||
// A field with the same identifier already exists.
|
||||
log.debug("Not collecting a field matching another with the same info:", info);
|
||||
continue;
|
||||
}
|
||||
|
||||
let formatWithElement = {
|
||||
section: info.section,
|
||||
addressType: info.addressType,
|
||||
contactType: info.contactType,
|
||||
fieldName: info.fieldName,
|
||||
elementWeakRef: Cu.getWeakReference(element),
|
||||
};
|
||||
|
||||
fieldDetails.push(formatWithElement);
|
||||
}
|
||||
|
||||
return fieldDetails;
|
||||
},
|
||||
|
||||
getInfo(element) {
|
||||
if (!(element instanceof Ci.nsIDOMHTMLInputElement)) {
|
||||
return null;
|
||||
|
|
Загрузка…
Ссылка в новой задаче