Try to more gracefully handle unexpected destruction of stylesheet linking

nodes.  Bug 185808 (just fixes the crash, not the real problem).  r=sicking,
sr=jst, a=dbaron
This commit is contained in:
bzbarsky%mit.edu 2003-02-04 04:45:58 +00:00
Родитель 6f7255ab44
Коммит 4e17c8c0d3
2 изменённых файлов: 22 добавлений и 9 удалений

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

@ -743,6 +743,8 @@ nsGenericElement::nsGenericElement()
nsGenericElement::~nsGenericElement()
{
NS_PRECONDITION(!mDocument, "Please remove this from the document properly");
// pop any enclosed ranges out
// nsRange::OwnerGone(mContent); not used for now
@ -790,7 +792,7 @@ nsGenericElement::~nsGenericElement()
delete slots;
}
// No calling GetFlags() beond this point...
// No calling GetFlags() beyond this point...
}
PR_STATIC_CALLBACK(void)

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

@ -48,13 +48,22 @@ nsStyleLinkElement::nsStyleLinkElement() :
nsStyleLinkElement::~nsStyleLinkElement()
{
nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(mStyleSheet);
if (cssSheet) {
cssSheet->SetOwningNode(nsnull);
}
}
NS_IMETHODIMP
nsStyleLinkElement::SetStyleSheet(nsIStyleSheet* aStyleSheet)
{
nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(mStyleSheet);
if (cssSheet) {
cssSheet->SetOwningNode(nsnull);
}
mStyleSheet = aStyleSheet;
nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(aStyleSheet);
cssSheet = do_QueryInterface(mStyleSheet);
if (cssSheet) {
nsCOMPtr<nsIDOMNode> node;
CallQueryInterface(this,
@ -166,6 +175,15 @@ NS_IMETHODIMP
nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument,
nsICSSLoaderObserver* aObserver)
{
if (mStyleSheet && aOldDocument) {
// We're removing the link element from the document, unload the
// stylesheet. We want to do this even if updates are disabled, since
// otherwise a sheet with a stale linking element pointer will be hanging
// around -- not good!
aOldDocument->RemoveStyleSheet(mStyleSheet);
mStyleSheet = nsnull;
}
if (mDontLoadStyle || !mUpdatesEnabled) {
return NS_OK;
}
@ -185,13 +203,6 @@ nsStyleLinkElement::UpdateStyleSheet(nsIDocument *aOldDocument,
nsCOMPtr<nsIDocument> doc;
thisContent->GetDocument(*getter_AddRefs(doc));
if (mStyleSheet && aOldDocument) {
// We're removing the link element from the document, unload the
// stylesheet.
aOldDocument->RemoveStyleSheet(mStyleSheet);
mStyleSheet = nsnull;
}
if (!doc) {
return NS_OK;
}