layout/svg/nsSVGMaskFrame.h

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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef __NS_SVGMASKFRAME_H__
     7 #define __NS_SVGMASKFRAME_H__
     9 #include "mozilla/Attributes.h"
    10 #include "gfxPattern.h"
    11 #include "gfxMatrix.h"
    12 #include "nsSVGContainerFrame.h"
    13 #include "nsSVGUtils.h"
    15 class gfxContext;
    16 class nsRenderingContext;
    18 typedef nsSVGContainerFrame nsSVGMaskFrameBase;
    20 class nsSVGMaskFrame : public nsSVGMaskFrameBase
    21 {
    22   friend nsIFrame*
    23   NS_NewSVGMaskFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    24 protected:
    25   nsSVGMaskFrame(nsStyleContext* aContext)
    26     : nsSVGMaskFrameBase(aContext)
    27     , mInUse(false)
    28   {
    29     AddStateBits(NS_FRAME_IS_NONDISPLAY);
    30   }
    32 public:
    33   NS_DECL_FRAMEARENA_HELPERS
    35   // nsSVGMaskFrame method:
    36   already_AddRefed<gfxPattern> ComputeMaskAlpha(nsRenderingContext *aContext,
    37                                                 nsIFrame* aParent,
    38                                                 const gfxMatrix &aMatrix,
    39                                                 float aOpacity = 1.0f);
    41   virtual nsresult AttributeChanged(int32_t         aNameSpaceID,
    42                                     nsIAtom*        aAttribute,
    43                                     int32_t         aModType) MOZ_OVERRIDE;
    45 #ifdef DEBUG
    46   virtual void Init(nsIContent*      aContent,
    47                     nsIFrame*        aParent,
    48                     nsIFrame*        aPrevInFlow) MOZ_OVERRIDE;
    49 #endif
    51   virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    52                                 const nsRect&           aDirtyRect,
    53                                 const nsDisplayListSet& aLists) MOZ_OVERRIDE {}
    55   /**
    56    * Get the "type" of the frame
    57    *
    58    * @see nsGkAtoms::svgMaskFrame
    59    */
    60   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    62 #ifdef DEBUG_FRAME_DUMP
    63   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
    64   {
    65     return MakeFrameName(NS_LITERAL_STRING("SVGMask"), aResult);
    66   }
    67 #endif
    69 private:
    70   // A helper class to allow us to paint masks safely. The helper
    71   // automatically sets and clears the mInUse flag on the mask frame
    72   // (to prevent nasty reference loops). It's easy to mess this up
    73   // and break things, so this helper makes the code far more robust.
    74   class MOZ_STACK_CLASS AutoMaskReferencer
    75   {
    76   public:
    77     AutoMaskReferencer(nsSVGMaskFrame *aFrame
    78                        MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
    79        : mFrame(aFrame) {
    80       MOZ_GUARD_OBJECT_NOTIFIER_INIT;
    81       NS_ASSERTION(!mFrame->mInUse, "reference loop!");
    82       mFrame->mInUse = true;
    83     }
    84     ~AutoMaskReferencer() {
    85       mFrame->mInUse = false;
    86     }
    87   private:
    88     nsSVGMaskFrame *mFrame;
    89     MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
    90   };
    92   nsIFrame *mMaskParent;
    93   nsAutoPtr<gfxMatrix> mMaskParentMatrix;
    94   // recursion prevention flag
    95   bool mInUse;
    97   // nsSVGContainerFrame methods:
    98   virtual gfxMatrix GetCanvasTM(uint32_t aFor,
    99                                 nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
   100 };
   102 #endif

mercurial