Bug 1400618 part 4 - Destroy frames before calling nsXBLBinding::ChangeDocument in a few places. r=bz

nsXBLBinding::ChangeDocument calls UnbindAnonymousContent
which calls UnbindFromTree on the content so any frames must be
destroyed before that to maintain the invariant that frames are
destroyed before unbinding.

MozReview-Commit-ID: 8Icj7zqpuZS
This commit is contained in:
Mats Palmgren 2017-11-07 01:20:34 +01:00
parent 3d465c6765
commit ac0c539c86
2 changed files with 14 additions and 2 deletions

View File

@ -276,6 +276,12 @@ nsBindingManager::ClearBinding(Element* aElement)
// ChangeDocument?
nsCOMPtr<nsIDocument> doc = aElement->OwnerDoc();
// Destroy the frames here before the UnbindFromTree happens.
nsIPresShell* presShell = doc->GetShell();
if (presShell) {
presShell->DestroyFramesForAndRestyle(aElement);
}
// Finally remove the binding...
// XXXbz this doesn't remove the implementation! Should fix! Until
// then we need the explicit UnhookEventHandlers here.
@ -288,7 +294,7 @@ nsBindingManager::ClearBinding(Element* aElement)
// been removed and style may have changed due to the removal of the
// anonymous children.
// XXXbz this should be using the current doc (if any), not the owner doc.
nsIPresShell *presShell = doc->GetShell();
presShell = doc->GetShell(); // get the shell again, just in case it changed
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
presShell->PostRecreateFramesFor(aElement);

View File

@ -48,7 +48,8 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocument* aDocument,
*aDidPrettyPrint = false;
// Check for iframe with display:none. Such iframes don't have presshells
if (!aDocument->GetShell()) {
nsIPresShell* shell = aDocument->GetShell();
if (!shell) {
return NS_OK;
}
@ -151,6 +152,11 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocument* aDocument,
nsContentUtils::GetSecurityManager()->
GetSystemPrincipal(getter_AddRefs(sysPrincipal));
// Destroy any existing frames before we unbind anonymous content.
if (rootCont->IsElement()) {
shell->DestroyFramesForAndRestyle(rootCont->AsElement());
}
// Load the bindings.
RefPtr<nsXBLBinding> unused;
bool ignored;