--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -133,17 +133,17 @@ class FormAutofillSection {
get allFieldNames() {
if (!this._cacheValue.allFieldNames) {
this._cacheValue.allFieldNames = this._validDetails.map(record => record.fieldName);
}
return this._cacheValue.allFieldNames;
}
- getFieldDetailByName(fieldName) {
+ _getFieldDetailByName(fieldName) {
return this._validDetails.find(detail => detail.fieldName == fieldName);
}
_getTargetSet() {
let fieldDetail = this._focusedDetail;
if (!fieldDetail) {
return null;
}
@@ -176,26 +176,26 @@ class FormAutofillSection {
return this._cacheValue.oneLineStreetAddress[address];
}
_addressTransformer(profile) {
if (profile["street-address"]) {
// "-moz-street-address-one-line" is used by the labels in
// ProfileAutoCompleteResult.
profile["-moz-street-address-one-line"] = this._getOneLineStreetAddress(profile["street-address"]);
- let streetAddressDetail = this.getFieldDetailByName("street-address");
+ let streetAddressDetail = this._getFieldDetailByName("street-address");
if (streetAddressDetail &&
(streetAddressDetail.elementWeakRef.get() instanceof Ci.nsIDOMHTMLInputElement)) {
profile["street-address"] = profile["-moz-street-address-one-line"];
}
let waitForConcat = [];
for (let f of ["address-line3", "address-line2", "address-line1"]) {
waitForConcat.unshift(profile[f]);
- if (this.getFieldDetailByName(f)) {
+ if (this._getFieldDetailByName(f)) {
if (waitForConcat.length > 1) {
profile[f] = FormAutofillUtils.toOneLineAddress(waitForConcat);
}
waitForConcat = [];
}
}
}
}
@@ -206,17 +206,17 @@ class FormAutofillSection {
* @param {Object} profile
* A profile to be converted.
*/
_telTransformer(profile) {
if (!profile.tel || !profile["tel-national"]) {
return;
}
- let detail = this.getFieldDetailByName("tel");
+ let detail = this._getFieldDetailByName("tel");
if (!detail) {
return;
}
let element = detail.elementWeakRef.get();
let _pattern;
let testPattern = str => {
if (!_pattern) {
@@ -255,17 +255,17 @@ class FormAutofillSection {
}
_matchSelectOptions(profile) {
if (!this._cacheValue.matchingSelectOption) {
this._cacheValue.matchingSelectOption = new WeakMap();
}
for (let fieldName in profile) {
- let fieldDetail = this.getFieldDetailByName(fieldName);
+ let fieldDetail = this._getFieldDetailByName(fieldName);
if (!fieldDetail) {
continue;
}
let element = fieldDetail.elementWeakRef.get();
if (ChromeUtils.getClassName(element) !== "HTMLSelectElement") {
continue;
}
@@ -292,17 +292,17 @@ class FormAutofillSection {
}
}
_creditCardExpDateTransformer(profile) {
if (!profile["cc-exp"]) {
return;
}
- let detail = this.getFieldDetailByName("cc-exp");
+ let detail = this._getFieldDetailByName("cc-exp");
if (!detail) {
return;
}
let element = detail.elementWeakRef.get();
if (element.tagName != "INPUT" || !element.placeholder) {
return;
}
@@ -325,17 +325,17 @@ class FormAutofillSection {
profile["cc-exp"] = String(ccExpYear).substr(-1 * result[1].length) +
result[2] +
String(ccExpMonth).padStart(result[3].length, "0");
}
}
_adaptFieldMaxLength(profile) {
for (let key in profile) {
- let detail = this.getFieldDetailByName(key);
+ let detail = this._getFieldDetailByName(key);
if (!detail) {
continue;
}
let element = detail.elementWeakRef.get();
if (!element) {
continue;
}
@@ -415,33 +415,33 @@ class FormAutofillSection {
// For the focused input element, it will be filled with a valid value
// anyway.
// For the others, the fields should be only filled when their values
// are empty.
let focusedInput = focusedDetail.elementWeakRef.get();
if (element == focusedInput ||
(element != focusedInput && !element.value)) {
element.setUserInput(value);
- this.changeFieldState(fieldDetail, FIELD_STATES.AUTO_FILLED);
+ this._changeFieldState(fieldDetail, FIELD_STATES.AUTO_FILLED);
}
} else if (ChromeUtils.getClassName(element) === "HTMLSelectElement") {
let cache = this._cacheValue.matchingSelectOption.get(element) || {};
let option = cache[value] && cache[value].get();
if (!option) {
continue;
}
// Do not change value or dispatch events if the option is already selected.
// Use case for multiple select is not considered here.
if (!option.selected) {
option.selected = true;
element.dispatchEvent(new element.ownerGlobal.UIEvent("input", {bubbles: true}));
element.dispatchEvent(new element.ownerGlobal.Event("change", {bubbles: true}));
}
// Autofill highlight appears regardless if value is changed or not
- this.changeFieldState(fieldDetail, FIELD_STATES.AUTO_FILLED);
+ this._changeFieldState(fieldDetail, FIELD_STATES.AUTO_FILLED);
}
if (fieldDetail.state == FIELD_STATES.AUTO_FILLED) {
element.addEventListener("input", this, {mozSystemGroup: true});
}
}
}
/**
@@ -481,17 +481,17 @@ class FormAutofillSection {
value = "";
}
}
} else if (element.value) {
// Skip the field if it already has text entered.
continue;
}
element.previewValue = value;
- this.changeFieldState(fieldDetail, value ? FIELD_STATES.PREVIEW : FIELD_STATES.NORMAL);
+ this._changeFieldState(fieldDetail, value ? FIELD_STATES.PREVIEW : FIELD_STATES.NORMAL);
}
}
/**
* Clear preview text and background highlight of all fields.
*/
clearPreviewedFormFields() {
log.debug("clear previewed fields in:", this.form);
@@ -507,17 +507,17 @@ class FormAutofillSection {
element.previewValue = "";
// We keep the state if this field has
// already been auto-filled.
if (fieldDetail.state == FIELD_STATES.AUTO_FILLED) {
continue;
}
- this.changeFieldState(fieldDetail, FIELD_STATES.NORMAL);
+ this._changeFieldState(fieldDetail, FIELD_STATES.NORMAL);
}
}
/**
* Clear value and highlight style of all filled fields.
*/
clearPopulatedForm() {
let fieldDetails = this._getFieldDetails();
@@ -540,17 +540,17 @@ class FormAutofillSection {
/**
* Change the state of a field to correspond with different presentations.
*
* @param {Object} fieldDetail
* A fieldDetail of which its element is about to update the state.
* @param {string} nextState
* Used to determine the next state
*/
- changeFieldState(fieldDetail, nextState) {
+ _changeFieldState(fieldDetail, nextState) {
let element = fieldDetail.elementWeakRef.get();
if (!element) {
log.warn(fieldDetail.fieldName, "is unreachable while changing state");
return;
}
if (!(nextState in this._FIELD_STATE_ENUM)) {
log.warn(fieldDetail.fieldName, "is trying to change to an invalid state");
@@ -573,17 +573,17 @@ class FormAutofillSection {
fieldDetail.state = nextState;
}
resetFieldStates() {
for (let fieldDetail of this._validDetails) {
const element = fieldDetail.elementWeakRef.get();
element.removeEventListener("input", this, {mozSystemGroup: true});
- this.changeFieldState(fieldDetail, FIELD_STATES.NORMAL);
+ this._changeFieldState(fieldDetail, FIELD_STATES.NORMAL);
}
this.address.filledRecordGUID = null;
this.creditCard.filledRecordGUID = null;
}
isFilled() {
return !!(this.address.filledRecordGUID || this.creditCard.filledRecordGUID);
}
@@ -704,17 +704,17 @@ class FormAutofillSection {
_normalizeAddress(address) {
if (!address) {
return;
}
// Normalize Country
if (address.record.country) {
- let detail = this.getFieldDetailByName("country");
+ let detail = this._getFieldDetailByName("country");
// Try identifying country field aggressively if it doesn't come from
// @autocomplete.
if (detail._reason != "autocomplete") {
let countryCode = FormAutofillUtils.identifyCountryCode(address.record.country);
if (countryCode) {
address.record.country = countryCode;
}
}
@@ -760,17 +760,17 @@ class FormAutofillSection {
switch (event.type) {
case "input": {
if (!event.isTrusted) {
return;
}
const target = event.target;
const fieldDetail = this.getFieldDetailByElement(target);
const targetSet = this._getTargetSet(target);
- this.changeFieldState(fieldDetail, FIELD_STATES.NORMAL);
+ this._changeFieldState(fieldDetail, FIELD_STATES.NORMAL);
if (!targetSet.fieldDetails.some(detail => detail.state == FIELD_STATES.AUTO_FILLED)) {
targetSet.filledRecordGUID = null;
}
target.removeEventListener("input", this, {mozSystemGroup: true});
break;
}
}
@@ -918,42 +918,42 @@ class FormAutofillHandler {
}
input.addEventListener("input", this, {mozSystemGroup: true});
}
this.fieldDetails = allValidDetails;
return allValidDetails;
}
- hasFilledSection() {
+ _hasFilledSection() {
return this.sections.some(section => section.isFilled());
}
/**
* Processes form fields that can be autofilled, and populates them with the
* profile provided by backend.
*
* @param {Object} profile
* A profile to be filled in.
*/
async autofillFormFields(profile) {
- let noFilledSectionsPreviously = !this.hasFilledSection();
+ let noFilledSectionsPreviously = !this._hasFilledSection();
await this.activeSection.autofillFields(profile);
const onChangeHandler = e => {
if (!e.isTrusted) {
return;
}
if (e.type == "reset") {
for (let section of this.sections) {
section.resetFieldStates();
}
}
// Unregister listeners once no field is in AUTO_FILLED state.
- if (!this.hasFilledSection()) {
+ if (!this._hasFilledSection()) {
this.form.rootElement.removeEventListener("input", onChangeHandler, {mozSystemGroup: true});
this.form.rootElement.removeEventListener("reset", onChangeHandler, {mozSystemGroup: true});
}
};
if (noFilledSectionsPreviously) {
// Handle the highlight style resetting caused by user's correction afterward.
log.debug("register change handler for filled form:", this.form);