Bug 1738980 - Do not notify autocomplete search result when the search operation is canceled. r=sfoster,tgiles

Before this patch, when the search operation is canceled, we return null
in _getRecords instead of returning `AutoCompleteResult`, See
https://searchfox.org/mozilla-central/rev/80fddabd6773cd028ec69dd4f5a2a34fcd6b4387/toolkit/components/formautofill/FormAutofillContent.jsm#255-271

However, a null result does stop us from calling onSearchResult callback, which triggers
an assertion in nsAutoCompleteController.
https://searchfox.org/mozilla-central/rev/80fddabd6773cd028ec69dd4f5a2a34fcd6b4387/toolkit/components/formautofill/FormAutofillContent.jsm#276-291
https://searchfox.org/mozilla-central/rev/1e7f7235cf822e79cd79ba9e200329ede3d37925/toolkit/components/autocomplete/nsAutoCompleteController.cpp#813

This patches check whether the search operation is canceled before calling `onSearchResult`.

Differential Revision: https://phabricator.services.mozilla.com/D130242
This commit is contained in:
Dimi 2021-11-05 15:44:40 +00:00
Родитель 4963e6b250
Коммит 4ffac0fbf3
1 изменённых файлов: 10 добавлений и 0 удалений

Просмотреть файл

@ -274,6 +274,16 @@ AutofillProfileAutoCompleteSearch.prototype = {
}
Promise.resolve(pendingSearchResult).then(result => {
if (this.forceStop) {
// If we notify the listener the search result when the search is already
// cancelled, it corrupts the internal state of the listener. So we only
// reset the controller's state in this case.
if (isFormAutofillSearch) {
autocompleteController.resetInternalState();
}
return;
}
listener.onSearchResult(this, result);
// Don't save cache results or reset state when returning non-autofill results such as the
// form history fallback above.