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 | // Keep in (case-insensitive) order: |
michael@0 | 7 | #include "gfxRect.h" |
michael@0 | 8 | #include "nsSVGEffects.h" |
michael@0 | 9 | #include "nsSVGGFrame.h" |
michael@0 | 10 | #include "mozilla/dom/SVGSwitchElement.h" |
michael@0 | 11 | #include "nsSVGUtils.h" |
michael@0 | 12 | |
michael@0 | 13 | class nsRenderingContext; |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla::gfx; |
michael@0 | 16 | |
michael@0 | 17 | typedef nsSVGGFrame nsSVGSwitchFrameBase; |
michael@0 | 18 | |
michael@0 | 19 | class nsSVGSwitchFrame : public nsSVGSwitchFrameBase |
michael@0 | 20 | { |
michael@0 | 21 | friend nsIFrame* |
michael@0 | 22 | NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
michael@0 | 23 | protected: |
michael@0 | 24 | nsSVGSwitchFrame(nsStyleContext* aContext) : |
michael@0 | 25 | nsSVGSwitchFrameBase(aContext) {} |
michael@0 | 26 | |
michael@0 | 27 | public: |
michael@0 | 28 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 29 | |
michael@0 | 30 | #ifdef DEBUG |
michael@0 | 31 | virtual void Init(nsIContent* aContent, |
michael@0 | 32 | nsIFrame* aParent, |
michael@0 | 33 | nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
michael@0 | 34 | #endif |
michael@0 | 35 | |
michael@0 | 36 | /** |
michael@0 | 37 | * Get the "type" of the frame |
michael@0 | 38 | * |
michael@0 | 39 | * @see nsGkAtoms::svgSwitchFrame |
michael@0 | 40 | */ |
michael@0 | 41 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 42 | |
michael@0 | 43 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 44 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
michael@0 | 45 | { |
michael@0 | 46 | return MakeFrameName(NS_LITERAL_STRING("SVGSwitch"), aResult); |
michael@0 | 47 | } |
michael@0 | 48 | #endif |
michael@0 | 49 | |
michael@0 | 50 | virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 51 | const nsRect& aDirtyRect, |
michael@0 | 52 | const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
michael@0 | 53 | |
michael@0 | 54 | // nsISVGChildFrame interface: |
michael@0 | 55 | virtual nsresult PaintSVG(nsRenderingContext* aContext, |
michael@0 | 56 | const nsIntRect *aDirtyRect, |
michael@0 | 57 | nsIFrame* aTransformRoot) MOZ_OVERRIDE; |
michael@0 | 58 | nsIFrame* GetFrameForPoint(const nsPoint &aPoint) MOZ_OVERRIDE; |
michael@0 | 59 | nsRect GetCoveredRegion() MOZ_OVERRIDE; |
michael@0 | 60 | virtual void ReflowSVG() MOZ_OVERRIDE; |
michael@0 | 61 | virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace, |
michael@0 | 62 | uint32_t aFlags) MOZ_OVERRIDE; |
michael@0 | 63 | |
michael@0 | 64 | private: |
michael@0 | 65 | nsIFrame *GetActiveChildFrame(); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | //---------------------------------------------------------------------- |
michael@0 | 69 | // Implementation |
michael@0 | 70 | |
michael@0 | 71 | nsIFrame* |
michael@0 | 72 | NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 73 | { |
michael@0 | 74 | return new (aPresShell) nsSVGSwitchFrame(aContext); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | NS_IMPL_FRAMEARENA_HELPERS(nsSVGSwitchFrame) |
michael@0 | 78 | |
michael@0 | 79 | #ifdef DEBUG |
michael@0 | 80 | void |
michael@0 | 81 | nsSVGSwitchFrame::Init(nsIContent* aContent, |
michael@0 | 82 | nsIFrame* aParent, |
michael@0 | 83 | nsIFrame* aPrevInFlow) |
michael@0 | 84 | { |
michael@0 | 85 | NS_ASSERTION(aContent->IsSVG(nsGkAtoms::svgSwitch), |
michael@0 | 86 | "Content is not an SVG switch"); |
michael@0 | 87 | |
michael@0 | 88 | nsSVGSwitchFrameBase::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 89 | } |
michael@0 | 90 | #endif /* DEBUG */ |
michael@0 | 91 | |
michael@0 | 92 | nsIAtom * |
michael@0 | 93 | nsSVGSwitchFrame::GetType() const |
michael@0 | 94 | { |
michael@0 | 95 | return nsGkAtoms::svgSwitchFrame; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | void |
michael@0 | 99 | nsSVGSwitchFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 100 | const nsRect& aDirtyRect, |
michael@0 | 101 | const nsDisplayListSet& aLists) |
michael@0 | 102 | { |
michael@0 | 103 | nsIFrame* kid = GetActiveChildFrame(); |
michael@0 | 104 | if (kid) { |
michael@0 | 105 | BuildDisplayListForChild(aBuilder, kid, aDirtyRect, aLists); |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | nsresult |
michael@0 | 110 | nsSVGSwitchFrame::PaintSVG(nsRenderingContext* aContext, |
michael@0 | 111 | const nsIntRect *aDirtyRect, |
michael@0 | 112 | nsIFrame* aTransformRoot) |
michael@0 | 113 | { |
michael@0 | 114 | NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() || |
michael@0 | 115 | (mState & NS_FRAME_IS_NONDISPLAY), |
michael@0 | 116 | "If display lists are enabled, only painting of non-display " |
michael@0 | 117 | "SVG should take this code path"); |
michael@0 | 118 | |
michael@0 | 119 | if (StyleDisplay()->mOpacity == 0.0) |
michael@0 | 120 | return NS_OK; |
michael@0 | 121 | |
michael@0 | 122 | nsIFrame *kid = GetActiveChildFrame(); |
michael@0 | 123 | if (kid) { |
michael@0 | 124 | nsSVGUtils::PaintFrameWithEffects(aContext, aDirtyRect, kid, aTransformRoot); |
michael@0 | 125 | } |
michael@0 | 126 | return NS_OK; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | |
michael@0 | 130 | nsIFrame* |
michael@0 | 131 | nsSVGSwitchFrame::GetFrameForPoint(const nsPoint &aPoint) |
michael@0 | 132 | { |
michael@0 | 133 | NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() || |
michael@0 | 134 | (mState & NS_FRAME_IS_NONDISPLAY), |
michael@0 | 135 | "If display lists are enabled, only hit-testing of non-display " |
michael@0 | 136 | "SVG should take this code path"); |
michael@0 | 137 | |
michael@0 | 138 | nsIFrame *kid = GetActiveChildFrame(); |
michael@0 | 139 | nsISVGChildFrame* svgFrame = do_QueryFrame(kid); |
michael@0 | 140 | if (svgFrame) { |
michael@0 | 141 | return svgFrame->GetFrameForPoint(aPoint); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | return nullptr; |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | nsRect |
michael@0 | 148 | nsSVGSwitchFrame::GetCoveredRegion() |
michael@0 | 149 | { |
michael@0 | 150 | nsRect rect; |
michael@0 | 151 | |
michael@0 | 152 | nsIFrame *kid = GetActiveChildFrame(); |
michael@0 | 153 | nsISVGChildFrame* child = do_QueryFrame(kid); |
michael@0 | 154 | if (child) { |
michael@0 | 155 | rect = child->GetCoveredRegion(); |
michael@0 | 156 | } |
michael@0 | 157 | return rect; |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | void |
michael@0 | 161 | nsSVGSwitchFrame::ReflowSVG() |
michael@0 | 162 | { |
michael@0 | 163 | NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this), |
michael@0 | 164 | "This call is probably a wasteful mistake"); |
michael@0 | 165 | |
michael@0 | 166 | NS_ABORT_IF_FALSE(!(GetStateBits() & NS_FRAME_IS_NONDISPLAY), |
michael@0 | 167 | "ReflowSVG mechanism not designed for this"); |
michael@0 | 168 | |
michael@0 | 169 | if (!nsSVGUtils::NeedsReflowSVG(this)) { |
michael@0 | 170 | return; |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | // If the NS_FRAME_FIRST_REFLOW bit has been removed from our parent frame, |
michael@0 | 174 | // then our outer-<svg> has previously had its initial reflow. In that case |
michael@0 | 175 | // we need to make sure that that bit has been removed from ourself _before_ |
michael@0 | 176 | // recursing over our children to ensure that they know too. Otherwise, we |
michael@0 | 177 | // need to remove it _after_ recursing over our children so that they know |
michael@0 | 178 | // the initial reflow is currently underway. |
michael@0 | 179 | |
michael@0 | 180 | bool isFirstReflow = (mState & NS_FRAME_FIRST_REFLOW); |
michael@0 | 181 | |
michael@0 | 182 | bool outerSVGHasHadFirstReflow = |
michael@0 | 183 | (GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW) == 0; |
michael@0 | 184 | |
michael@0 | 185 | if (outerSVGHasHadFirstReflow) { |
michael@0 | 186 | mState &= ~NS_FRAME_FIRST_REFLOW; // tell our children |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | nsOverflowAreas overflowRects; |
michael@0 | 190 | |
michael@0 | 191 | nsIFrame *child = GetActiveChildFrame(); |
michael@0 | 192 | nsISVGChildFrame* svgChild = do_QueryFrame(child); |
michael@0 | 193 | if (svgChild) { |
michael@0 | 194 | NS_ABORT_IF_FALSE(!(child->GetStateBits() & NS_FRAME_IS_NONDISPLAY), |
michael@0 | 195 | "Check for this explicitly in the |if|, then"); |
michael@0 | 196 | svgChild->ReflowSVG(); |
michael@0 | 197 | |
michael@0 | 198 | // We build up our child frame overflows here instead of using |
michael@0 | 199 | // nsLayoutUtils::UnionChildOverflow since SVG frame's all use the same |
michael@0 | 200 | // frame list, and we're iterating over that list now anyway. |
michael@0 | 201 | ConsiderChildOverflow(overflowRects, child); |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | if (isFirstReflow) { |
michael@0 | 205 | // Make sure we have our filter property (if any) before calling |
michael@0 | 206 | // FinishAndStoreOverflow (subsequent filter changes are handled off |
michael@0 | 207 | // nsChangeHint_UpdateEffects): |
michael@0 | 208 | nsSVGEffects::UpdateEffects(this); |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | FinishAndStoreOverflow(overflowRects, mRect.Size()); |
michael@0 | 212 | |
michael@0 | 213 | // Remove state bits after FinishAndStoreOverflow so that it doesn't |
michael@0 | 214 | // invalidate on first reflow: |
michael@0 | 215 | mState &= ~(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY | |
michael@0 | 216 | NS_FRAME_HAS_DIRTY_CHILDREN); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | SVGBBox |
michael@0 | 220 | nsSVGSwitchFrame::GetBBoxContribution(const Matrix &aToBBoxUserspace, |
michael@0 | 221 | uint32_t aFlags) |
michael@0 | 222 | { |
michael@0 | 223 | nsIFrame* kid = GetActiveChildFrame(); |
michael@0 | 224 | nsISVGChildFrame* svgKid = do_QueryFrame(kid); |
michael@0 | 225 | if (svgKid) { |
michael@0 | 226 | nsIContent *content = kid->GetContent(); |
michael@0 | 227 | gfxMatrix transform = ThebesMatrix(aToBBoxUserspace); |
michael@0 | 228 | if (content->IsSVG()) { |
michael@0 | 229 | transform = static_cast<nsSVGElement*>(content)-> |
michael@0 | 230 | PrependLocalTransformsTo(transform); |
michael@0 | 231 | } |
michael@0 | 232 | return svgKid->GetBBoxContribution(ToMatrix(transform), aFlags); |
michael@0 | 233 | } |
michael@0 | 234 | return SVGBBox(); |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | nsIFrame * |
michael@0 | 238 | nsSVGSwitchFrame::GetActiveChildFrame() |
michael@0 | 239 | { |
michael@0 | 240 | nsIContent *activeChild = |
michael@0 | 241 | static_cast<mozilla::dom::SVGSwitchElement*>(mContent)->GetActiveChild(); |
michael@0 | 242 | |
michael@0 | 243 | if (activeChild) { |
michael@0 | 244 | for (nsIFrame* kid = mFrames.FirstChild(); kid; |
michael@0 | 245 | kid = kid->GetNextSibling()) { |
michael@0 | 246 | |
michael@0 | 247 | if (activeChild == kid->GetContent()) { |
michael@0 | 248 | return kid; |
michael@0 | 249 | } |
michael@0 | 250 | } |
michael@0 | 251 | } |
michael@0 | 252 | return nullptr; |
michael@0 | 253 | } |