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 "nsContentUtils.h" |
michael@0 | 8 | #include "nsFrame.h" |
michael@0 | 9 | #include "nsGkAtoms.h" |
michael@0 | 10 | #include "nsLiteralString.h" |
michael@0 | 11 | #include "nsSVGEffects.h" |
michael@0 | 12 | #include "nsSVGFilters.h" |
michael@0 | 13 | #include "mozilla/dom/SVGFEImageElement.h" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla; |
michael@0 | 16 | using namespace mozilla::dom; |
michael@0 | 17 | |
michael@0 | 18 | typedef nsFrame SVGFEImageFrameBase; |
michael@0 | 19 | |
michael@0 | 20 | class SVGFEImageFrame : public SVGFEImageFrameBase |
michael@0 | 21 | { |
michael@0 | 22 | friend nsIFrame* |
michael@0 | 23 | NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
michael@0 | 24 | protected: |
michael@0 | 25 | SVGFEImageFrame(nsStyleContext* aContext) |
michael@0 | 26 | : SVGFEImageFrameBase(aContext) |
michael@0 | 27 | { |
michael@0 | 28 | AddStateBits(NS_FRAME_SVG_LAYOUT | NS_FRAME_IS_NONDISPLAY); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | public: |
michael@0 | 32 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 33 | |
michael@0 | 34 | virtual void Init(nsIContent* aContent, |
michael@0 | 35 | nsIFrame* aParent, |
michael@0 | 36 | nsIFrame* aPrevInFlow) MOZ_OVERRIDE; |
michael@0 | 37 | virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
michael@0 | 38 | |
michael@0 | 39 | virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
michael@0 | 40 | { |
michael@0 | 41 | return SVGFEImageFrameBase::IsFrameOfType(aFlags & ~(nsIFrame::eSVG)); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 45 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
michael@0 | 46 | { |
michael@0 | 47 | return MakeFrameName(NS_LITERAL_STRING("SVGFEImage"), aResult); |
michael@0 | 48 | } |
michael@0 | 49 | #endif |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * Get the "type" of the frame |
michael@0 | 53 | * |
michael@0 | 54 | * @see nsGkAtoms::svgFEImageFrame |
michael@0 | 55 | */ |
michael@0 | 56 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 57 | |
michael@0 | 58 | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 59 | nsIAtom* aAttribute, |
michael@0 | 60 | int32_t aModType) MOZ_OVERRIDE; |
michael@0 | 61 | |
michael@0 | 62 | virtual bool UpdateOverflow() MOZ_OVERRIDE { |
michael@0 | 63 | // We don't maintain a visual overflow rect |
michael@0 | 64 | return false; |
michael@0 | 65 | } |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | nsIFrame* |
michael@0 | 69 | NS_NewSVGFEImageFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) |
michael@0 | 70 | { |
michael@0 | 71 | return new (aPresShell) SVGFEImageFrame(aContext); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | NS_IMPL_FRAMEARENA_HELPERS(SVGFEImageFrame) |
michael@0 | 75 | |
michael@0 | 76 | /* virtual */ void |
michael@0 | 77 | SVGFEImageFrame::DestroyFrom(nsIFrame* aDestructRoot) |
michael@0 | 78 | { |
michael@0 | 79 | nsCOMPtr<nsIImageLoadingContent> imageLoader = |
michael@0 | 80 | do_QueryInterface(SVGFEImageFrameBase::mContent); |
michael@0 | 81 | |
michael@0 | 82 | if (imageLoader) { |
michael@0 | 83 | imageLoader->FrameDestroyed(this); |
michael@0 | 84 | imageLoader->DecrementVisibleCount(); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | SVGFEImageFrameBase::DestroyFrom(aDestructRoot); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | void |
michael@0 | 91 | SVGFEImageFrame::Init(nsIContent* aContent, |
michael@0 | 92 | nsIFrame* aParent, |
michael@0 | 93 | nsIFrame* aPrevInFlow) |
michael@0 | 94 | { |
michael@0 | 95 | NS_ASSERTION(aContent->IsSVG(nsGkAtoms::feImage), |
michael@0 | 96 | "Trying to construct an SVGFEImageFrame for a " |
michael@0 | 97 | "content element that doesn't support the right interfaces"); |
michael@0 | 98 | |
michael@0 | 99 | SVGFEImageFrameBase::Init(aContent, aParent, aPrevInFlow); |
michael@0 | 100 | nsCOMPtr<nsIImageLoadingContent> imageLoader = |
michael@0 | 101 | do_QueryInterface(SVGFEImageFrameBase::mContent); |
michael@0 | 102 | |
michael@0 | 103 | if (imageLoader) { |
michael@0 | 104 | // We assume that feImage's are always visible. |
michael@0 | 105 | // Increment the visible count before calling FrameCreated so that |
michael@0 | 106 | // FrameCreated will actually track the image correctly. |
michael@0 | 107 | imageLoader->IncrementVisibleCount(); |
michael@0 | 108 | imageLoader->FrameCreated(this); |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | nsIAtom * |
michael@0 | 113 | SVGFEImageFrame::GetType() const |
michael@0 | 114 | { |
michael@0 | 115 | return nsGkAtoms::svgFEImageFrame; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | nsresult |
michael@0 | 119 | SVGFEImageFrame::AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 120 | nsIAtom* aAttribute, |
michael@0 | 121 | int32_t aModType) |
michael@0 | 122 | { |
michael@0 | 123 | SVGFEImageElement *element = static_cast<SVGFEImageElement*>(mContent); |
michael@0 | 124 | if (element->AttributeAffectsRendering(aNameSpaceID, aAttribute)) { |
michael@0 | 125 | nsSVGEffects::InvalidateRenderingObservers(this); |
michael@0 | 126 | } |
michael@0 | 127 | if (aNameSpaceID == kNameSpaceID_XLink && |
michael@0 | 128 | aAttribute == nsGkAtoms::href) { |
michael@0 | 129 | |
michael@0 | 130 | // Prevent setting image.src by exiting early |
michael@0 | 131 | if (nsContentUtils::IsImageSrcSetDisabled()) { |
michael@0 | 132 | return NS_OK; |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | if (element->mStringAttributes[SVGFEImageElement::HREF].IsExplicitlySet()) { |
michael@0 | 136 | element->LoadSVGImage(true, true); |
michael@0 | 137 | } else { |
michael@0 | 138 | element->CancelImageRequests(true); |
michael@0 | 139 | } |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | return SVGFEImageFrameBase::AttributeChanged(aNameSpaceID, |
michael@0 | 143 | aAttribute, aModType); |
michael@0 | 144 | } |