Bug 1867886: Ensure that NotificationController can't re-register with the refresh driver after it's been unregistered in Shutdown. r=eeejay

This is just a "belt-and-suspenders" invariant tightening.  Shouldn't impact
behavior at all, assuming that we don't call methods on NotificationController
objects that have been nerfed with Shutdown().

Differential Revision: https://phabricator.services.mozilla.com/D195321
This commit is contained in:
Daniel Holbert
2023-12-04 20:42:05 +00:00
parent 45a064e6b8
commit 6e38919bf1

View File

@@ -92,6 +92,9 @@ void NotificationController::Shutdown() {
MOZ_RELEASE_ASSERT(mObservingState == eNotObservingRefresh,
"Must unregister before being destroyed (and we just "
"passed our last change to unregister)");
// Immediately null out mPresShell, to prevent us from being registered as a
// refresh observer again.
mPresShell = nullptr;
// Shutdown handling child documents.
int32_t childDocCount = mHangingChildDocuments.Length();
@@ -104,7 +107,6 @@ void NotificationController::Shutdown() {
mHangingChildDocuments.Clear();
mDocument = nullptr;
mPresShell = nullptr;
mTextArray.Clear();
mContentInsertions.Clear();
@@ -459,9 +461,11 @@ void NotificationController::ScheduleContentInsertion(
}
void NotificationController::ScheduleProcessing() {
// If notification flush isn't planed yet start notification flush
// If notification flush isn't planned yet, start notification flush
// asynchronously (after style and layout).
if (mObservingState == eNotObservingRefresh) {
// Note: the mPresShell null-check might be unnecessary; it's just to prevent
// a null-deref here, if we somehow get called after we've been shut down.
if (mObservingState == eNotObservingRefresh && mPresShell) {
if (mPresShell->AddRefreshObserver(this, FlushType::Display,
"Accessibility notifications")) {
mObservingState = eRefreshObserving;