layout/svg/SVGViewFrame.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 "nsFrame.h"
michael@0 8 #include "nsGkAtoms.h"
michael@0 9 #include "nsSVGOuterSVGFrame.h"
michael@0 10 #include "mozilla/dom/SVGSVGElement.h"
michael@0 11 #include "mozilla/dom/SVGViewElement.h"
michael@0 12
michael@0 13 typedef nsFrame SVGViewFrameBase;
michael@0 14
michael@0 15 using namespace mozilla::dom;
michael@0 16
michael@0 17 /**
michael@0 18 * While views are not directly rendered in SVG they can be linked to
michael@0 19 * and thereby override attributes of an <svg> element via a fragment
michael@0 20 * identifier. The SVGViewFrame class passes on any attribute changes
michael@0 21 * the view receives to the overridden <svg> element (if there is one).
michael@0 22 **/
michael@0 23 class SVGViewFrame : public SVGViewFrameBase
michael@0 24 {
michael@0 25 friend nsIFrame*
michael@0 26 NS_NewSVGViewFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
michael@0 27 protected:
michael@0 28 SVGViewFrame(nsStyleContext* aContext)
michael@0 29 : SVGViewFrameBase(aContext)
michael@0 30 {
michael@0 31 AddStateBits(NS_FRAME_IS_NONDISPLAY);
michael@0 32 }
michael@0 33
michael@0 34 public:
michael@0 35 NS_DECL_FRAMEARENA_HELPERS
michael@0 36
michael@0 37 #ifdef DEBUG
michael@0 38 virtual void Init(nsIContent* aContent,
michael@0 39 nsIFrame* aParent,
michael@0 40 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
michael@0 41 #endif
michael@0 42
michael@0 43 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
michael@0 44 {
michael@0 45 return SVGViewFrameBase::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
michael@0 46 }
michael@0 47
michael@0 48 #ifdef DEBUG_FRAME_DUMP
michael@0 49 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
michael@0 50 {
michael@0 51 return MakeFrameName(NS_LITERAL_STRING("SVGView"), aResult);
michael@0 52 }
michael@0 53 #endif
michael@0 54
michael@0 55 /**
michael@0 56 * Get the "type" of the frame
michael@0 57 *
michael@0 58 * @see nsGkAtoms::svgFELeafFrame
michael@0 59 */
michael@0 60 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 61
michael@0 62 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
michael@0 63 nsIAtom* aAttribute,
michael@0 64 int32_t aModType) MOZ_OVERRIDE;
michael@0 65
michael@0 66 virtual bool UpdateOverflow() MOZ_OVERRIDE {
michael@0 67 // We don't maintain a visual overflow rect
michael@0 68 return false;
michael@0 69 }
michael@0 70 };
michael@0 71
michael@0 72 nsIFrame*
michael@0 73 NS_NewSVGViewFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
michael@0 74 {
michael@0 75 return new (aPresShell) SVGViewFrame(aContext);
michael@0 76 }
michael@0 77
michael@0 78 NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame)
michael@0 79
michael@0 80 #ifdef DEBUG
michael@0 81 void
michael@0 82 SVGViewFrame::Init(nsIContent* aContent,
michael@0 83 nsIFrame* aParent,
michael@0 84 nsIFrame* aPrevInFlow)
michael@0 85 {
michael@0 86 NS_ASSERTION(aContent->IsSVG(nsGkAtoms::view),
michael@0 87 "Content is not an SVG view");
michael@0 88
michael@0 89 SVGViewFrameBase::Init(aContent, aParent, aPrevInFlow);
michael@0 90 }
michael@0 91 #endif /* DEBUG */
michael@0 92
michael@0 93 nsIAtom *
michael@0 94 SVGViewFrame::GetType() const
michael@0 95 {
michael@0 96 return nsGkAtoms::svgViewFrame;
michael@0 97 }
michael@0 98
michael@0 99 nsresult
michael@0 100 SVGViewFrame::AttributeChanged(int32_t aNameSpaceID,
michael@0 101 nsIAtom* aAttribute,
michael@0 102 int32_t aModType)
michael@0 103 {
michael@0 104 // Ignore zoomAndPan as it does not cause the <svg> element to re-render
michael@0 105
michael@0 106 if (aNameSpaceID == kNameSpaceID_None &&
michael@0 107 (aAttribute == nsGkAtoms::preserveAspectRatio ||
michael@0 108 aAttribute == nsGkAtoms::viewBox ||
michael@0 109 aAttribute == nsGkAtoms::viewTarget)) {
michael@0 110
michael@0 111 nsSVGOuterSVGFrame *outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(this);
michael@0 112 NS_ASSERTION(outerSVGFrame->GetContent()->IsSVG(nsGkAtoms::svg),
michael@0 113 "Expecting an <svg> element");
michael@0 114
michael@0 115 SVGSVGElement* svgElement =
michael@0 116 static_cast<SVGSVGElement*>(outerSVGFrame->GetContent());
michael@0 117
michael@0 118 nsAutoString viewID;
michael@0 119 mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, viewID);
michael@0 120
michael@0 121 if (svgElement->IsOverriddenBy(viewID)) {
michael@0 122 // We're the view that's providing overrides, so pretend that the frame
michael@0 123 // we're overriding was updated.
michael@0 124 outerSVGFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
michael@0 125 }
michael@0 126 }
michael@0 127
michael@0 128 return SVGViewFrameBase::AttributeChanged(aNameSpaceID,
michael@0 129 aAttribute, aModType);
michael@0 130 }

mercurial