Bug 1115812 patch 19 - Avoid bad kungFuDeathGrip pattern. r=heycam

If we need a strong reference to the pres shell, we may as well do it
the first time rather than bothering with an extra variable.
This commit is contained in:
L. David Baron 2015-01-13 21:03:12 -08:00
parent 0e8362d05a
commit 7bc8463f0e

View File

@ -1480,7 +1480,10 @@ RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
NS_UpdateHint(mRebuildAllExtraHint, aExtraHint);
mRebuildAllRestyleHint |= aRestyleHint;
nsIPresShell* presShell = mPresContext->GetPresShell();
// Processing the style changes could cause a flush that propagates to
// the parent frame and thus destroys the pres shell, so we must hold
// a reference.
nsCOMPtr<nsIPresShell> presShell = mPresContext->GetPresShell();
if (!presShell || !presShell->GetRootFrame()) {
mDoRebuildAllStyleData = false;
return;
@ -1489,10 +1492,6 @@ RestyleManager::RebuildAllStyleData(nsChangeHint aExtraHint,
// Make sure that the viewmanager will outlive the presshell
nsRefPtr<nsViewManager> vm = presShell->GetViewManager();
// Processing the style changes could cause a flush that propagates to
// the parent frame and thus destroys the pres shell.
nsCOMPtr<nsIPresShell> kungFuDeathGrip(presShell);
// We may reconstruct frames below and hence process anything that is in the
// tree. We don't want to get notified to process those items again after.
presShell->GetDocument()->FlushPendingNotifications(Flush_ContentAndNotify);