Bug 1259303 - Properly cancel login manager async searches to avoid assertions. r=MattN

This commit is contained in:
Blake Kaplan 2016-04-12 12:19:58 -07:00
Родитель f858198ac3
Коммит d056b90405
3 изменённых файлов: 28 добавлений и 8 удалений

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

@ -215,6 +215,11 @@ interface nsILoginManager : nsISupports {
in nsIDOMHTMLInputElement aElement,
in nsIFormAutoCompleteObserver aListener);
/**
* Stop a previously-started async search.
*/
void stopSearch();
/**
* Search for logins in the login manager. An array is always returned;
* if there are no logins the array is empty.

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

@ -88,6 +88,7 @@ LoginManager.prototype = {
this._prefBranch.addObserver("rememberSignons", this._observer, false);
this._remember = this._prefBranch.getBoolPref("rememberSignons");
this._autoCompleteLookupPromise = null;
// Form submit observer checks forms for new logins and pw changes.
Services.obs.addObserver(this._observer, "xpcom-shutdown", false);
@ -461,14 +462,26 @@ LoginManager.prototype = {
}
let rect = BrowserUtils.getElementBoundingScreenRect(aElement);
LoginManagerContent._autoCompleteSearchAsync(aSearchString, previousResult,
aElement, rect)
.then(function({ logins, messageManager }) {
let results =
new UserAutoCompleteResult(aSearchString, logins, messageManager);
aCallback.onSearchCompletion(results);
})
.then(null, Cu.reportError);
let autoCompleteLookupPromise = this._autoCompleteLookupPromise =
LoginManagerContent._autoCompleteSearchAsync(aSearchString, previousResult,
aElement, rect);
autoCompleteLookupPromise.then(({ logins, messageManager }) => {
// If the search was canceled before we got our
// results, don't bother reporting them.
if (this._autoCompleteLookupPromise !== autoCompleteLookupPromise) {
return;
}
this._autoCompleteLookupPromise = null;
let results =
new UserAutoCompleteResult(aSearchString, logins, messageManager);
aCallback.onSearchCompletion(results);
})
.then(null, Cu.reportError);
},
stopSearch() {
this._autoCompleteLookupPromise = null;
},
}; // end of LoginManager implementation

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

@ -774,6 +774,8 @@ nsFormFillController::StopSearch()
if (mLastFormAutoComplete) {
mLastFormAutoComplete->StopAutoCompleteSearch();
mLastFormAutoComplete = nullptr;
} else if (mLoginManager) {
mLoginManager->StopSearch();
}
return NS_OK;
}