Bug 1349477, part 1 - Use AutoReferenceChainGuard in nsSVGFilterFrame. r=longsonr

MozReview-Commit-ID: HTcySIH3qNt
This commit is contained in:
Jonathan Watt committed 2017-02-21 09:37:09 +00:00
1 parent 01828ef0b4
commit 1336548a4c
2 files changed
+43 -51

No files matched your search

+43 -49
View File
@@ -7,6 +7,7 @@
#include "nsSVGFilterFrame.h"
// Keep others in (case-insensitive) order:
#include "AutoReferenceChainGuard.h"
#include "gfxUtils.h"
#include "nsGkAtoms.h"
#include "nsSVGEffects.h"
@@ -17,6 +18,7 @@
#include "nsSVGUtils.h"
#include "nsContentUtils.h"
using namespace mozilla;
using namespace mozilla::dom;
nsIFrame*
@@ -27,26 +29,6 @@ NS_NewSVGFilterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
NS_IMPL_FRAMEARENA_HELPERS(nsSVGFilterFrame)
class MOZ_RAII nsSVGFilterFrame::AutoFilterReferencer
{
public:
explicit AutoFilterReferencer(nsSVGFilterFrame *aFrame MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mFrame(aFrame)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
// Reference loops should normally be detected in advance and handled, so
// we're not expecting to encounter them here
MOZ_ASSERT(!mFrame->mLoopFlag, "Undetected reference loop!");
mFrame->mLoopFlag = true;
}
~AutoFilterReferencer() {
mFrame->mLoopFlag = false;
}
private:
nsSVGFilterFrame *mFrame;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
uint16_t
nsSVGFilterFrame::GetEnumValue(uint32_t aIndex, nsIContent *aDefault)
{
@@ -56,12 +38,22 @@ nsSVGFilterFrame::GetEnumValue(uint32_t aIndex, nsIContent *aDefault)
if (thisEnum.IsExplicitlySet())
return thisEnum.GetAnimValue();
AutoFilterReferencer filterRef(this);
// Before we recurse, make sure we'll break reference loops and over long
// reference chains:
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
AutoReferenceChainGuard refChainGuard(this, &mLoopFlag,
&sRefChainLengthCounter);
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
// Break reference chain
return static_cast<SVGFilterElement *>(aDefault)->
mEnumAttributes[aIndex].GetAnimValue();
}
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
return next ? next->GetEnumValue(aIndex, aDefault) :
static_cast<SVGFilterElement *>(aDefault)->
mEnumAttributes[aIndex].GetAnimValue();
nsSVGFilterFrame *next = GetReferencedFilter();
return next ? next->GetEnumValue(aIndex, aDefault)
: static_cast<SVGFilterElement *>(aDefault)->
mEnumAttributes[aIndex].GetAnimValue();
}
const nsSVGLength2 *
@@ -73,11 +65,20 @@ nsSVGFilterFrame::GetLengthValue(uint32_t aIndex, nsIContent *aDefault)
if (thisLength->IsExplicitlySet())
return thisLength;
AutoFilterReferencer filterRef(this);
// Before we recurse, make sure we'll break reference loops and over long
// reference chains:
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
AutoReferenceChainGuard refChainGuard(this, &mLoopFlag,
&sRefChainLengthCounter);
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
// Break reference chain
return &static_cast<SVGFilterElement*>(aDefault)->mLengthAttributes[aIndex];
}
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
return next ? next->GetLengthValue(aIndex, aDefault) :
&static_cast<SVGFilterElement *>(aDefault)->mLengthAttributes[aIndex];
nsSVGFilterFrame *next = GetReferencedFilter();
return next ? next->GetLengthValue(aIndex, aDefault)
: &static_cast<SVGFilterElement *>(aDefault)->mLengthAttributes[aIndex];
}
const SVGFilterElement *
@@ -93,11 +94,20 @@ nsSVGFilterFrame::GetFilterContent(nsIContent *aDefault)
}
}
AutoFilterReferencer filterRef(this);
// Before we recurse, make sure we'll break reference loops and over long
// reference chains:
static int16_t sRefChainLengthCounter = AutoReferenceChainGuard::noChain;
AutoReferenceChainGuard refChainGuard(this, &mLoopFlag,
&sRefChainLengthCounter);
if (MOZ_UNLIKELY(!refChainGuard.Reference())) {
// Break reference chain
return static_cast<SVGFilterElement*>(aDefault);
}
nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse();
return next ? next->GetFilterContent(aDefault) :
static_cast<SVGFilterElement *>(aDefault);
nsSVGFilterFrame *next = GetReferencedFilter();
return next ? next->GetFilterContent(aDefault)
: static_cast<SVGFilterElement*>(aDefault);
}
nsSVGFilterFrame *
@@ -150,22 +160,6 @@ nsSVGFilterFrame::GetReferencedFilter()
return static_cast<nsSVGFilterFrame*>(result);
}
nsSVGFilterFrame *
nsSVGFilterFrame::GetReferencedFilterIfNotInUse()
{
nsSVGFilterFrame *referenced = GetReferencedFilter();
if (!referenced)
return nullptr;
if (referenced->mLoopFlag) {
// XXXjwatt: we should really send an error to the JavaScript Console here:
NS_WARNING("Filter reference loop detected while inheriting attribute!");
return nullptr;
}
return referenced;
}
nsresult
nsSVGFilterFrame::AttributeChanged(int32_t aNameSpaceID,
nsIAtom* aAttribute,
-2
View File
@@ -69,10 +69,8 @@ private:
// Parse our xlink:href and set up our nsSVGPaintingProperty if we
// reference another filter and we don't have a property. Return
// the referenced filter's frame if available, null otherwise.
class AutoFilterReferencer;
friend class nsSVGFilterInstance;
nsSVGFilterFrame* GetReferencedFilter();
nsSVGFilterFrame* GetReferencedFilterIfNotInUse();
// Accessors to lookup filter attributes
uint16_t GetEnumValue(uint32_t aIndex, nsIContent *aDefault);