mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
Bug 1339731
- Refactor some duplicated codes and remove the unused method. r=lchang,ralin
MozReview-Commit-ID: 5BHR2sJBASl --HG-- extra : rebase_source : b0cc20356a2b72c5047c475562475b877831c41d
This commit is contained in:
parent
bc4a3d74f8
commit
747b26c501
@ -102,9 +102,8 @@ AutofillProfileAutoCompleteSearch.prototype = {
|
||||
let info = FormAutofillContent.getInputDetails(focusedInput);
|
||||
let isAddressField = FormAutofillUtils.isAddressField(info.fieldName);
|
||||
let handler = FormAutofillContent.getFormHandler(focusedInput);
|
||||
let section = handler.getSectionByElement(focusedInput);
|
||||
let allFieldNames = section.allFieldNames;
|
||||
let filledRecordGUID = isAddressField ? section.address.filledRecordGUID : section.creditCard.filledRecordGUID;
|
||||
let allFieldNames = handler.getAllFieldNames(focusedInput);
|
||||
let filledRecordGUID = handler.getFilledRecordGUID(focusedInput);
|
||||
let searchPermitted = isAddressField ?
|
||||
FormAutofillUtils.isAutofillAddressesEnabled :
|
||||
FormAutofillUtils.isAutofillCreditCardsEnabled;
|
||||
|
@ -136,18 +136,28 @@ class FormAutofillSection {
|
||||
return this._validDetails.find(detail => detail.fieldName == fieldName);
|
||||
}
|
||||
|
||||
getFieldDetailsByElement(element) {
|
||||
_getTargetSet(element) {
|
||||
let fieldDetail = this.getFieldDetailByElement(element);
|
||||
if (!fieldDetail) {
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
if (FormAutofillUtils.isAddressField(fieldDetail.fieldName)) {
|
||||
return this.address.fieldDetails;
|
||||
return this.address;
|
||||
}
|
||||
if (FormAutofillUtils.isCreditCardField(fieldDetail.fieldName)) {
|
||||
return this.creditCard.fieldDetails;
|
||||
return this.creditCard;
|
||||
}
|
||||
return [];
|
||||
return null;
|
||||
}
|
||||
|
||||
getFieldDetailsByElement(element) {
|
||||
let targetSet = this._getTargetSet(element);
|
||||
return targetSet ? targetSet.fieldDetails : [];
|
||||
}
|
||||
|
||||
getFilledRecordGUID(element) {
|
||||
let targetSet = this._getTargetSet(element);
|
||||
return targetSet ? targetSet.filledRecordGUID : null;
|
||||
}
|
||||
|
||||
_getOneLineStreetAddress(address) {
|
||||
@ -337,7 +347,7 @@ class FormAutofillSection {
|
||||
if (!focusedDetail) {
|
||||
throw new Error("No fieldDetail for the focused input.");
|
||||
}
|
||||
let targetSet;
|
||||
let targetSet = this._getTargetSet(focusedInput);
|
||||
if (FormAutofillUtils.isCreditCardField(focusedDetail.fieldName)) {
|
||||
// When Master Password is enabled by users, the decryption process
|
||||
// should prompt Master Password dialog to get the decrypted credit
|
||||
@ -353,11 +363,6 @@ class FormAutofillSection {
|
||||
|
||||
profile["cc-number"] = decrypted;
|
||||
}
|
||||
targetSet = this.creditCard;
|
||||
} else if (FormAutofillUtils.isAddressField(focusedDetail.fieldName)) {
|
||||
targetSet = this.address;
|
||||
} else {
|
||||
throw new Error("Unknown form fields");
|
||||
}
|
||||
|
||||
log.debug("profile in autofillFields:", profile);
|
||||
@ -526,12 +531,7 @@ class FormAutofillSection {
|
||||
clearFieldState(focusedInput) {
|
||||
let fieldDetail = this.getFieldDetailByElement(focusedInput);
|
||||
this.changeFieldState(fieldDetail, "NORMAL");
|
||||
let targetSet;
|
||||
if (FormAutofillUtils.isAddressField(focusedInput)) {
|
||||
targetSet = this.address;
|
||||
} else if (FormAutofillUtils.isCreditCardField(focusedInput)) {
|
||||
targetSet = this.creditCard;
|
||||
}
|
||||
let targetSet = this._getTargetSet(focusedInput);
|
||||
|
||||
if (!targetSet.fieldDetails.some(detail => detail.state == "AUTO_FILLED")) {
|
||||
targetSet.filledRecordGUID = null;
|
||||
@ -813,6 +813,7 @@ class FormAutofillHandler {
|
||||
this.fieldDetails = null;
|
||||
|
||||
this.sections = [];
|
||||
this._sectionCache = new WeakMap();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -844,24 +845,15 @@ class FormAutofillHandler {
|
||||
return allValidDetails;
|
||||
}
|
||||
|
||||
getFieldDetailByElement(element) {
|
||||
return this.fieldDetails.find(
|
||||
detail => detail.elementWeakRef.get() == element
|
||||
);
|
||||
}
|
||||
|
||||
getSectionByElement(element) {
|
||||
return this.sections.find(
|
||||
section => section.getFieldDetailByElement(element)
|
||||
);
|
||||
}
|
||||
|
||||
getFieldDetailsByElement(element) {
|
||||
let fieldDetail = this.getFieldDetailByElement(element);
|
||||
if (!fieldDetail) {
|
||||
return [];
|
||||
let section = this._sectionCache.get(element);
|
||||
if (!section) {
|
||||
section = this.sections.find(
|
||||
s => s.getFieldDetailByElement(element)
|
||||
);
|
||||
this._sectionCache.set(element, section);
|
||||
}
|
||||
return this.getSectionByElement(element).getFieldDetailsByElement(element);
|
||||
return section;
|
||||
}
|
||||
|
||||
getAllFieldNames(focusedInput) {
|
||||
@ -879,6 +871,11 @@ class FormAutofillHandler {
|
||||
section.clearPreviewedFormFields(focusedInput);
|
||||
}
|
||||
|
||||
getFilledRecordGUID(focusedInput) {
|
||||
let section = this.getSectionByElement(focusedInput);
|
||||
return section.getFilledRecordGUID(focusedInput);
|
||||
}
|
||||
|
||||
getAdaptedProfiles(originalProfiles, focusedInput) {
|
||||
let section = this.getSectionByElement(focusedInput);
|
||||
section.getAdaptedProfiles(originalProfiles);
|
||||
|
Loading…
Reference in New Issue
Block a user