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.

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

mercurial