content/media/TextTrackRegion.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 /* vim:set ts=2 sw=2 et tw=78: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef mozilla_dom_TextTrackRegion_h
     8 #define mozilla_dom_TextTrackRegion_h
    10 #include "nsAutoPtr.h"
    11 #include "nsCycleCollectionParticipant.h"
    12 #include "nsString.h"
    13 #include "nsWrapperCache.h"
    14 #include "mozilla/ErrorResult.h"
    15 #include "mozilla/dom/TextTrack.h"
    16 #include "mozilla/Preferences.h"
    18 namespace mozilla {
    19 namespace dom {
    21 class GlobalObject;
    22 class TextTrack;
    24 class TextTrackRegion MOZ_FINAL : public nsISupports,
    25                                   public nsWrapperCache
    26 {
    27 public:
    29   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    30   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TextTrackRegion)
    32   static bool RegionsEnabled(JSContext* cx, JSObject* obj)
    33   {
    34     return Preferences::GetBool("media.webvtt.enabled") &&
    35            Preferences::GetBool("media.webvtt.regions.enabled");
    36   }
    38   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    40   nsISupports* GetParentObject() const
    41   {
    42     return mParent;
    43   }
    45   TextTrackRegion(nsISupports* aGlobal);
    47   /** WebIDL Methods. */
    49   static already_AddRefed<TextTrackRegion>
    50   Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
    52   double Lines() const
    53   {
    54     return mLines;
    55   }
    57   void SetLines(double aLines)
    58   {
    59     mLines = aLines;
    60   }
    62   double Width() const
    63   {
    64     return mWidth;
    65   }
    67   void SetWidth(double aWidth, ErrorResult& aRv)
    68   {
    69     if (!InvalidValue(aWidth, aRv)) {
    70       mWidth = aWidth;
    71     }
    72   }
    74   double RegionAnchorX() const
    75   {
    76     return mRegionAnchorX;
    77   }
    79   void SetRegionAnchorX(double aVal, ErrorResult& aRv)
    80   {
    81     if (!InvalidValue(aVal, aRv)) {
    82       mRegionAnchorX = aVal;
    83     }
    84   }
    86   double RegionAnchorY() const
    87   {
    88     return mRegionAnchorY;
    89   }
    91   void SetRegionAnchorY(double aVal, ErrorResult& aRv)
    92   {
    93     if (!InvalidValue(aVal, aRv)) {
    94       mRegionAnchorY = aVal;
    95     }
    96   }
    98   double ViewportAnchorX() const
    99   {
   100     return mViewportAnchorX;
   101   }
   103   void SetViewportAnchorX(double aVal, ErrorResult& aRv)
   104   {
   105     if (!InvalidValue(aVal, aRv)) {
   106       mViewportAnchorX = aVal;
   107     }
   108   }
   110   double ViewportAnchorY() const
   111   {
   112     return mViewportAnchorY;
   113   }
   115   void SetViewportAnchorY(double aVal, ErrorResult& aRv)
   116   {
   117     if (!InvalidValue(aVal, aRv)) {
   118       mViewportAnchorY = aVal;
   119     }
   120   }
   122   void GetScroll(nsAString& aScroll) const
   123   {
   124     aScroll = mScroll;
   125   }
   127   void SetScroll(const nsAString& aScroll, ErrorResult& aRv)
   128   {
   129     if (!aScroll.EqualsLiteral("") && !aScroll.EqualsLiteral("up")) {
   130       aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
   131       return;
   132     }
   134     mScroll = aScroll;
   135   }
   137   /** end WebIDL Methods. */
   140   // Helper to aid copying of a given TextTrackRegion's width, lines,
   141   // anchor, viewport and scroll values.
   142   void CopyValues(TextTrackRegion& aRegion);
   144   // -----helpers-------
   145   const nsAString& Scroll() const
   146   {
   147     return mScroll;
   148   }
   150 private:
   151   nsCOMPtr<nsISupports> mParent;
   152   double mWidth;
   153   long mLines;
   154   double mRegionAnchorX;
   155   double mRegionAnchorY;
   156   double mViewportAnchorX;
   157   double mViewportAnchorY;
   158   nsString mScroll;
   160   // Helper to ensure new value is in the range: 0.0% - 100.0%; throws
   161   // an IndexSizeError otherwise.
   162   inline bool InvalidValue(double aValue, ErrorResult& aRv)
   163   {
   164     if(aValue < 0.0  || aValue > 100.0) {
   165       aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
   166       return true;
   167     }
   169     return false;
   170   }
   172 };
   174 } //namespace dom
   175 } //namespace mozilla
   177 #endif //mozilla_dom_TextTrackRegion_h

mercurial