Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // Main header first: |
michael@0 | 7 | #include "nsSVGFilterFrame.h" |
michael@0 | 8 | |
michael@0 | 9 | // Keep others in (case-insensitive) order: |
michael@0 | 10 | #include "gfxUtils.h" |
michael@0 | 11 | #include "nsGkAtoms.h" |
michael@0 | 12 | #include "nsRenderingContext.h" |
michael@0 | 13 | #include "nsSVGEffects.h" |
michael@0 | 14 | #include "nsSVGElement.h" |
michael@0 | 15 | #include "mozilla/dom/SVGFilterElement.h" |
michael@0 | 16 | #include "nsSVGFilterInstance.h" |
michael@0 | 17 | #include "nsSVGFilterPaintCallback.h" |
michael@0 | 18 | #include "nsSVGIntegrationUtils.h" |
michael@0 | 19 | #include "nsSVGUtils.h" |
michael@0 | 20 | #include "nsContentUtils.h" |
michael@0 | 21 | |
michael@0 | 22 | using namespace mozilla::dom; |
michael@0 | 23 | |
michael@0 | 24 | nsIFrame* |
michael@0 | 25 | NS_NewSVGFilterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 26 | { |
michael@0 | 27 | return new (aPresShell) nsSVGFilterFrame(aContext); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | NS_IMPL_FRAMEARENA_HELPERS(nsSVGFilterFrame) |
michael@0 | 31 | |
michael@0 | 32 | class MOZ_STACK_CLASS nsSVGFilterFrame::AutoFilterReferencer |
michael@0 | 33 | { |
michael@0 | 34 | public: |
michael@0 | 35 | AutoFilterReferencer(nsSVGFilterFrame *aFrame MOZ_GUARD_OBJECT_NOTIFIER_PARAM) |
michael@0 | 36 | : mFrame(aFrame) |
michael@0 | 37 | { |
michael@0 | 38 | MOZ_GUARD_OBJECT_NOTIFIER_INIT; |
michael@0 | 39 | // Reference loops should normally be detected in advance and handled, so |
michael@0 | 40 | // we're not expecting to encounter them here |
michael@0 | 41 | NS_ABORT_IF_FALSE(!mFrame->mLoopFlag, "Undetected reference loop!"); |
michael@0 | 42 | mFrame->mLoopFlag = true; |
michael@0 | 43 | } |
michael@0 | 44 | ~AutoFilterReferencer() { |
michael@0 | 45 | mFrame->mLoopFlag = false; |
michael@0 | 46 | } |
michael@0 | 47 | private: |
michael@0 | 48 | nsSVGFilterFrame *mFrame; |
michael@0 | 49 | MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | uint16_t |
michael@0 | 53 | nsSVGFilterFrame::GetEnumValue(uint32_t aIndex, nsIContent *aDefault) |
michael@0 | 54 | { |
michael@0 | 55 | nsSVGEnum& thisEnum = |
michael@0 | 56 | static_cast<SVGFilterElement *>(mContent)->mEnumAttributes[aIndex]; |
michael@0 | 57 | |
michael@0 | 58 | if (thisEnum.IsExplicitlySet()) |
michael@0 | 59 | return thisEnum.GetAnimValue(); |
michael@0 | 60 | |
michael@0 | 61 | AutoFilterReferencer filterRef(this); |
michael@0 | 62 | |
michael@0 | 63 | nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse(); |
michael@0 | 64 | return next ? next->GetEnumValue(aIndex, aDefault) : |
michael@0 | 65 | static_cast<SVGFilterElement *>(aDefault)-> |
michael@0 | 66 | mEnumAttributes[aIndex].GetAnimValue(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | const nsSVGLength2 * |
michael@0 | 70 | nsSVGFilterFrame::GetLengthValue(uint32_t aIndex, nsIContent *aDefault) |
michael@0 | 71 | { |
michael@0 | 72 | const nsSVGLength2 *thisLength = |
michael@0 | 73 | &static_cast<SVGFilterElement *>(mContent)->mLengthAttributes[aIndex]; |
michael@0 | 74 | |
michael@0 | 75 | if (thisLength->IsExplicitlySet()) |
michael@0 | 76 | return thisLength; |
michael@0 | 77 | |
michael@0 | 78 | AutoFilterReferencer filterRef(this); |
michael@0 | 79 | |
michael@0 | 80 | nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse(); |
michael@0 | 81 | return next ? next->GetLengthValue(aIndex, aDefault) : |
michael@0 | 82 | &static_cast<SVGFilterElement *>(aDefault)->mLengthAttributes[aIndex]; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | const SVGFilterElement * |
michael@0 | 86 | nsSVGFilterFrame::GetFilterContent(nsIContent *aDefault) |
michael@0 | 87 | { |
michael@0 | 88 | for (nsIContent* child = mContent->GetFirstChild(); |
michael@0 | 89 | child; |
michael@0 | 90 | child = child->GetNextSibling()) { |
michael@0 | 91 | nsRefPtr<nsSVGFE> primitive; |
michael@0 | 92 | CallQueryInterface(child, (nsSVGFE**)getter_AddRefs(primitive)); |
michael@0 | 93 | if (primitive) { |
michael@0 | 94 | return static_cast<SVGFilterElement *>(mContent); |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | AutoFilterReferencer filterRef(this); |
michael@0 | 99 | |
michael@0 | 100 | nsSVGFilterFrame *next = GetReferencedFilterIfNotInUse(); |
michael@0 | 101 | return next ? next->GetFilterContent(aDefault) : |
michael@0 | 102 | static_cast<SVGFilterElement *>(aDefault); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | nsSVGFilterFrame * |
michael@0 | 106 | nsSVGFilterFrame::GetReferencedFilter() |
michael@0 | 107 | { |
michael@0 | 108 | if (mNoHRefURI) |
michael@0 | 109 | return nullptr; |
michael@0 | 110 | |
michael@0 | 111 | nsSVGPaintingProperty *property = static_cast<nsSVGPaintingProperty*> |
michael@0 | 112 | (Properties().Get(nsSVGEffects::HrefProperty())); |
michael@0 | 113 | |
michael@0 | 114 | if (!property) { |
michael@0 | 115 | // Fetch our Filter element's xlink:href attribute |
michael@0 | 116 | SVGFilterElement *filter = static_cast<SVGFilterElement *>(mContent); |
michael@0 | 117 | nsAutoString href; |
michael@0 | 118 | filter->mStringAttributes[SVGFilterElement::HREF].GetAnimValue(href, filter); |
michael@0 | 119 | if (href.IsEmpty()) { |
michael@0 | 120 | mNoHRefURI = true; |
michael@0 | 121 | return nullptr; // no URL |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | // Convert href to an nsIURI |
michael@0 | 125 | nsCOMPtr<nsIURI> targetURI; |
michael@0 | 126 | nsCOMPtr<nsIURI> base = mContent->GetBaseURI(); |
michael@0 | 127 | nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), href, |
michael@0 | 128 | mContent->GetCurrentDoc(), base); |
michael@0 | 129 | |
michael@0 | 130 | property = |
michael@0 | 131 | nsSVGEffects::GetPaintingProperty(targetURI, this, nsSVGEffects::HrefProperty()); |
michael@0 | 132 | if (!property) |
michael@0 | 133 | return nullptr; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | nsIFrame *result = property->GetReferencedFrame(); |
michael@0 | 137 | if (!result) |
michael@0 | 138 | return nullptr; |
michael@0 | 139 | |
michael@0 | 140 | nsIAtom* frameType = result->GetType(); |
michael@0 | 141 | if (frameType != nsGkAtoms::svgFilterFrame) |
michael@0 | 142 | return nullptr; |
michael@0 | 143 | |
michael@0 | 144 | return static_cast<nsSVGFilterFrame*>(result); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | nsSVGFilterFrame * |
michael@0 | 148 | nsSVGFilterFrame::GetReferencedFilterIfNotInUse() |
michael@0 | 149 | { |
michael@0 | 150 | nsSVGFilterFrame *referenced = GetReferencedFilter(); |
michael@0 | 151 | if (!referenced) |
michael@0 | 152 | return nullptr; |
michael@0 | 153 | |
michael@0 | 154 | if (referenced->mLoopFlag) { |
michael@0 | 155 | // XXXjwatt: we should really send an error to the JavaScript Console here: |
michael@0 | 156 | NS_WARNING("Filter reference loop detected while inheriting attribute!"); |
michael@0 | 157 | return nullptr; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | return referenced; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | nsresult |
michael@0 | 164 | nsSVGFilterFrame::AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 165 | nsIAtom* aAttribute, |
michael@0 | 166 | int32_t aModType) |
michael@0 | 167 | { |
michael@0 | 168 | if (aNameSpaceID == kNameSpaceID_None && |
michael@0 | 169 | (aAttribute == nsGkAtoms::x || |
michael@0 | 170 | aAttribute == nsGkAtoms::y || |
michael@0 | 171 | aAttribute == nsGkAtoms::width || |
michael@0 | 172 | aAttribute == nsGkAtoms::height || |
michael@0 | 173 | aAttribute == nsGkAtoms::filterUnits || |
michael@0 | 174 | aAttribute == nsGkAtoms::primitiveUnits)) { |
michael@0 | 175 | nsSVGEffects::InvalidateDirectRenderingObservers(this); |
michael@0 | 176 | } else if (aNameSpaceID == kNameSpaceID_XLink && |
michael@0 | 177 | aAttribute == nsGkAtoms::href) { |
michael@0 | 178 | // Blow away our reference, if any |
michael@0 | 179 | Properties().Delete(nsSVGEffects::HrefProperty()); |
michael@0 | 180 | mNoHRefURI = false; |
michael@0 | 181 | // And update whoever references us |
michael@0 | 182 | nsSVGEffects::InvalidateDirectRenderingObservers(this); |
michael@0 | 183 | } |
michael@0 | 184 | return nsSVGFilterFrameBase::AttributeChanged(aNameSpaceID, |
michael@0 | 185 | aAttribute, aModType); |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | #ifdef DEBUG |
michael@0 | 189 | void |
michael@0 | 190 | nsSVGFilterFrame::Init(nsIContent* aContent, |
michael@0 | 191 | nsIFrame* aParent, |
michael@0 | 192 | nsIFrame* aPrevInFlow) |
michael@0 | 193 | { |
michael@0 | 194 | NS_ASSERTION(aContent->IsSVG(nsGkAtoms::filter), |
michael@0 | 195 | "Content is not an SVG filter"); |
michael@0 | 196 | |
michael@0 | 197 | nsSVGFilterFrameBase::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 198 | } |
michael@0 | 199 | #endif /* DEBUG */ |
michael@0 | 200 | |
michael@0 | 201 | nsIAtom * |
michael@0 | 202 | nsSVGFilterFrame::GetType() const |
michael@0 | 203 | { |
michael@0 | 204 | return nsGkAtoms::svgFilterFrame; |
michael@0 | 205 | } |