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