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 "gfxMatrix.h" |
michael@0 | 8 | #include "mozilla/dom/SVGAElement.h" |
michael@0 | 9 | #include "nsSVGContainerFrame.h" |
michael@0 | 10 | #include "nsSVGIntegrationUtils.h" |
michael@0 | 11 | #include "nsSVGUtils.h" |
michael@0 | 12 | #include "SVGLengthList.h" |
michael@0 | 13 | |
michael@0 | 14 | using namespace mozilla; |
michael@0 | 15 | |
michael@0 | 16 | typedef nsSVGDisplayContainerFrame nsSVGAFrameBase; |
michael@0 | 17 | |
michael@0 | 18 | class nsSVGAFrame : public nsSVGAFrameBase |
michael@0 | 19 | { |
michael@0 | 20 | friend nsIFrame* |
michael@0 | 21 | NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
michael@0 | 22 | protected: |
michael@0 | 23 | nsSVGAFrame(nsStyleContext* aContext) : |
michael@0 | 24 | nsSVGAFrameBase(aContext) {} |
michael@0 | 25 | |
michael@0 | 26 | public: |
michael@0 | 27 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 28 | |
michael@0 | 29 | #ifdef DEBUG |
michael@0 | 30 | virtual void Init(nsIContent* aContent, |
michael@0 | 31 | nsIFrame* aParent, |
michael@0 | 32 | nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
michael@0 | 33 | #endif |
michael@0 | 34 | |
michael@0 | 35 | // nsIFrame: |
michael@0 | 36 | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 37 | nsIAtom* aAttribute, |
michael@0 | 38 | int32_t aModType) MOZ_OVERRIDE; |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Get the "type" of the frame |
michael@0 | 42 | * |
michael@0 | 43 | * @see nsGkAtoms::svgAFrame |
michael@0 | 44 | */ |
michael@0 | 45 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 46 | |
michael@0 | 47 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 48 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
michael@0 | 49 | { |
michael@0 | 50 | return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult); |
michael@0 | 51 | } |
michael@0 | 52 | #endif |
michael@0 | 53 | // nsISVGChildFrame interface: |
michael@0 | 54 | virtual void NotifySVGChanged(uint32_t aFlags) MOZ_OVERRIDE; |
michael@0 | 55 | |
michael@0 | 56 | // nsSVGContainerFrame methods: |
michael@0 | 57 | virtual gfxMatrix GetCanvasTM(uint32_t aFor, |
michael@0 | 58 | nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE; |
michael@0 | 59 | |
michael@0 | 60 | private: |
michael@0 | 61 | nsAutoPtr<gfxMatrix> mCanvasTM; |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | //---------------------------------------------------------------------- |
michael@0 | 65 | // Implementation |
michael@0 | 66 | |
michael@0 | 67 | nsIFrame* |
michael@0 | 68 | NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 69 | { |
michael@0 | 70 | return new (aPresShell) nsSVGAFrame(aContext); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame) |
michael@0 | 74 | |
michael@0 | 75 | //---------------------------------------------------------------------- |
michael@0 | 76 | // nsIFrame methods |
michael@0 | 77 | #ifdef DEBUG |
michael@0 | 78 | void |
michael@0 | 79 | nsSVGAFrame::Init(nsIContent* aContent, |
michael@0 | 80 | nsIFrame* aParent, |
michael@0 | 81 | nsIFrame* aPrevInFlow) |
michael@0 | 82 | { |
michael@0 | 83 | NS_ASSERTION(aContent->IsSVG(nsGkAtoms::a), |
michael@0 | 84 | "Trying to construct an SVGAFrame for a " |
michael@0 | 85 | "content element that doesn't support the right interfaces"); |
michael@0 | 86 | |
michael@0 | 87 | nsSVGAFrameBase::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 88 | } |
michael@0 | 89 | #endif /* DEBUG */ |
michael@0 | 90 | |
michael@0 | 91 | nsresult |
michael@0 | 92 | nsSVGAFrame::AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 93 | nsIAtom* aAttribute, |
michael@0 | 94 | int32_t aModType) |
michael@0 | 95 | { |
michael@0 | 96 | if (aNameSpaceID == kNameSpaceID_None && |
michael@0 | 97 | aAttribute == nsGkAtoms::transform) { |
michael@0 | 98 | // We don't invalidate for transform changes (the layers code does that). |
michael@0 | 99 | // Also note that SVGTransformableElement::GetAttributeChangeHint will |
michael@0 | 100 | // return nsChangeHint_UpdateOverflow for "transform" attribute changes |
michael@0 | 101 | // and cause DoApplyRenderingChangeToTree to make the SchedulePaint call. |
michael@0 | 102 | NotifySVGChanged(TRANSFORM_CHANGED); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | return NS_OK; |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | nsIAtom * |
michael@0 | 109 | nsSVGAFrame::GetType() const |
michael@0 | 110 | { |
michael@0 | 111 | return nsGkAtoms::svgAFrame; |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | //---------------------------------------------------------------------- |
michael@0 | 115 | // nsISVGChildFrame methods |
michael@0 | 116 | |
michael@0 | 117 | void |
michael@0 | 118 | nsSVGAFrame::NotifySVGChanged(uint32_t aFlags) |
michael@0 | 119 | { |
michael@0 | 120 | NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED), |
michael@0 | 121 | "Invalidation logic may need adjusting"); |
michael@0 | 122 | |
michael@0 | 123 | if (aFlags & TRANSFORM_CHANGED) { |
michael@0 | 124 | // make sure our cached transform matrix gets (lazily) updated |
michael@0 | 125 | mCanvasTM = nullptr; |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | nsSVGAFrameBase::NotifySVGChanged(aFlags); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | //---------------------------------------------------------------------- |
michael@0 | 132 | // nsSVGContainerFrame methods: |
michael@0 | 133 | |
michael@0 | 134 | gfxMatrix |
michael@0 | 135 | nsSVGAFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot) |
michael@0 | 136 | { |
michael@0 | 137 | if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) { |
michael@0 | 138 | if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) || |
michael@0 | 139 | (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) { |
michael@0 | 140 | return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this); |
michael@0 | 141 | } |
michael@0 | 142 | } |
michael@0 | 143 | if (!mCanvasTM) { |
michael@0 | 144 | NS_ASSERTION(mParent, "null parent"); |
michael@0 | 145 | |
michael@0 | 146 | nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent); |
michael@0 | 147 | dom::SVGAElement *content = static_cast<dom::SVGAElement*>(mContent); |
michael@0 | 148 | |
michael@0 | 149 | gfxMatrix tm = content->PrependLocalTransformsTo( |
michael@0 | 150 | this == aTransformRoot ? gfxMatrix() : |
michael@0 | 151 | parent->GetCanvasTM(aFor, aTransformRoot)); |
michael@0 | 152 | |
michael@0 | 153 | mCanvasTM = new gfxMatrix(tm); |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | return *mCanvasTM; |
michael@0 | 157 | } |