зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1300989 - Part 2: Use a WeakMap to store form autofill details.; r=MattN
MozReview-Commit-ID: AkfZnXQ2MkL --HG-- extra : rebase_source : 477c984b3495301df0a9e49bb6b00d16a16c90c6 extra : histedit_source : ba52dd5a6a0fee98d7e70d36e11b01254bfdd4fb
This commit is contained in:
Родитель
60e157bd14
Коммит
7b0e51ac72
|
@ -249,7 +249,10 @@ let ProfileAutocomplete = {
|
|||
* NOTE: Declares it by "var" to make it accessible in unit tests.
|
||||
*/
|
||||
var FormAutofillContent = {
|
||||
_formsDetails: [],
|
||||
/**
|
||||
* @type {WeakMap} mapping FormLike root HTML elements to form details.
|
||||
*/
|
||||
_formsDetails: new WeakMap(),
|
||||
|
||||
init() {
|
||||
Services.cpmm.addMessageListener("FormAutofill:enabledStatus", (result) => {
|
||||
|
@ -273,11 +276,10 @@ var FormAutofillContent = {
|
|||
* (or return null if the information is not found in the cache).
|
||||
*/
|
||||
getInputDetails(element) {
|
||||
for (let formDetails of this._formsDetails) {
|
||||
for (let detail of formDetails) {
|
||||
if (element == detail.element) {
|
||||
return detail;
|
||||
}
|
||||
let formDetails = this.getFormDetails(element);
|
||||
for (let detail of formDetails) {
|
||||
if (element == detail.element) {
|
||||
return detail;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -293,12 +295,9 @@ var FormAutofillContent = {
|
|||
*
|
||||
*/
|
||||
getFormDetails(element) {
|
||||
for (let formDetails of this._formsDetails) {
|
||||
if (formDetails.some((detail) => detail.element == element)) {
|
||||
return formDetails;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
let rootElement = FormLikeFactory.findRootForField(element);
|
||||
let formDetails = this._formsDetails.get(rootElement);
|
||||
return formDetails ? formDetails.fieldDetails : null;
|
||||
},
|
||||
|
||||
getAllFieldNames(element) {
|
||||
|
@ -332,7 +331,7 @@ var FormAutofillContent = {
|
|||
return;
|
||||
}
|
||||
|
||||
this._formsDetails.push(formHandler.fieldDetails);
|
||||
this._formsDetails.set(form.rootElement, formHandler);
|
||||
formHandler.fieldDetails.forEach(
|
||||
detail => this._markAsAutofillField(detail.element));
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче