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.
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 #include "nsSMILFloatType.h"
7 #include "nsSMILValue.h"
8 #include "nsDebug.h"
9 #include <math.h>
11 void
12 nsSMILFloatType::Init(nsSMILValue& aValue) const
13 {
14 NS_PRECONDITION(aValue.IsNull(), "Unexpected value type");
15 aValue.mU.mDouble = 0.0;
16 aValue.mType = this;
17 }
19 void
20 nsSMILFloatType::Destroy(nsSMILValue& aValue) const
21 {
22 NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value");
23 aValue.mU.mDouble = 0.0;
24 aValue.mType = nsSMILNullType::Singleton();
25 }
27 nsresult
28 nsSMILFloatType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const
29 {
30 NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types");
31 NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value");
32 aDest.mU.mDouble = aSrc.mU.mDouble;
33 return NS_OK;
34 }
36 bool
37 nsSMILFloatType::IsEqual(const nsSMILValue& aLeft,
38 const nsSMILValue& aRight) const
39 {
40 NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types");
41 NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value");
43 return aLeft.mU.mDouble == aRight.mU.mDouble;
44 }
46 nsresult
47 nsSMILFloatType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd,
48 uint32_t aCount) const
49 {
50 NS_PRECONDITION(aValueToAdd.mType == aDest.mType,
51 "Trying to add invalid types");
52 NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type");
53 aDest.mU.mDouble += aValueToAdd.mU.mDouble * aCount;
54 return NS_OK;
55 }
57 nsresult
58 nsSMILFloatType::ComputeDistance(const nsSMILValue& aFrom,
59 const nsSMILValue& aTo,
60 double& aDistance) const
61 {
62 NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types");
63 NS_PRECONDITION(aFrom.mType == this, "Unexpected source type");
65 const double &from = aFrom.mU.mDouble;
66 const double &to = aTo.mU.mDouble;
68 aDistance = fabs(to - from);
70 return NS_OK;
71 }
73 nsresult
74 nsSMILFloatType::Interpolate(const nsSMILValue& aStartVal,
75 const nsSMILValue& aEndVal,
76 double aUnitDistance,
77 nsSMILValue& aResult) const
78 {
79 NS_PRECONDITION(aStartVal.mType == aEndVal.mType,
80 "Trying to interpolate different types");
81 NS_PRECONDITION(aStartVal.mType == this,
82 "Unexpected types for interpolation");
83 NS_PRECONDITION(aResult.mType == this, "Unexpected result type");
85 const double &startVal = aStartVal.mU.mDouble;
86 const double &endVal = aEndVal.mU.mDouble;
88 aResult.mU.mDouble = (startVal + (endVal - startVal) * aUnitDistance);
90 return NS_OK;
91 }