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 "SMILIntegerType.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 | namespace mozilla { |
michael@0 | 12 | |
michael@0 | 13 | void |
michael@0 | 14 | SMILIntegerType::Init(nsSMILValue& aValue) const |
michael@0 | 15 | { |
michael@0 | 16 | NS_ABORT_IF_FALSE(aValue.IsNull(), "Unexpected value type"); |
michael@0 | 17 | aValue.mU.mInt = 0; |
michael@0 | 18 | aValue.mType = this; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | void |
michael@0 | 22 | SMILIntegerType::Destroy(nsSMILValue& aValue) const |
michael@0 | 23 | { |
michael@0 | 24 | NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); |
michael@0 | 25 | aValue.mU.mInt = 0; |
michael@0 | 26 | aValue.mType = nsSMILNullType::Singleton(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | nsresult |
michael@0 | 30 | SMILIntegerType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const |
michael@0 | 31 | { |
michael@0 | 32 | NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types"); |
michael@0 | 33 | NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value"); |
michael@0 | 34 | aDest.mU.mInt = aSrc.mU.mInt; |
michael@0 | 35 | return NS_OK; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | bool |
michael@0 | 39 | SMILIntegerType::IsEqual(const nsSMILValue& aLeft, |
michael@0 | 40 | const nsSMILValue& aRight) const |
michael@0 | 41 | { |
michael@0 | 42 | NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types"); |
michael@0 | 43 | NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value"); |
michael@0 | 44 | |
michael@0 | 45 | return aLeft.mU.mInt == aRight.mU.mInt; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | nsresult |
michael@0 | 49 | SMILIntegerType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd, |
michael@0 | 50 | uint32_t aCount) const |
michael@0 | 51 | { |
michael@0 | 52 | NS_PRECONDITION(aValueToAdd.mType == aDest.mType, |
michael@0 | 53 | "Trying to add invalid types"); |
michael@0 | 54 | NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type"); |
michael@0 | 55 | aDest.mU.mInt += aValueToAdd.mU.mInt * aCount; |
michael@0 | 56 | return NS_OK; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | nsresult |
michael@0 | 60 | SMILIntegerType::ComputeDistance(const nsSMILValue& aFrom, |
michael@0 | 61 | const nsSMILValue& aTo, |
michael@0 | 62 | double& aDistance) const |
michael@0 | 63 | { |
michael@0 | 64 | NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types"); |
michael@0 | 65 | NS_PRECONDITION(aFrom.mType == this, "Unexpected source type"); |
michael@0 | 66 | aDistance = fabs(double(aTo.mU.mInt - aFrom.mU.mInt)); |
michael@0 | 67 | return NS_OK; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | nsresult |
michael@0 | 71 | SMILIntegerType::Interpolate(const nsSMILValue& aStartVal, |
michael@0 | 72 | const nsSMILValue& aEndVal, |
michael@0 | 73 | double aUnitDistance, |
michael@0 | 74 | nsSMILValue& aResult) const |
michael@0 | 75 | { |
michael@0 | 76 | NS_PRECONDITION(aStartVal.mType == aEndVal.mType, |
michael@0 | 77 | "Trying to interpolate different types"); |
michael@0 | 78 | NS_PRECONDITION(aStartVal.mType == this, |
michael@0 | 79 | "Unexpected types for interpolation"); |
michael@0 | 80 | NS_PRECONDITION(aResult.mType == this, "Unexpected result type"); |
michael@0 | 81 | |
michael@0 | 82 | const double startVal = double(aStartVal.mU.mInt); |
michael@0 | 83 | const double endVal = double(aEndVal.mU.mInt); |
michael@0 | 84 | const double currentVal = startVal + (endVal - startVal) * aUnitDistance; |
michael@0 | 85 | |
michael@0 | 86 | // When currentVal is exactly midway between its two nearest integers, we |
michael@0 | 87 | // jump to the "next" integer to provide simple, easy to remember and |
michael@0 | 88 | // consistent behaviour (from the SMIL author's point of view). |
michael@0 | 89 | |
michael@0 | 90 | if (startVal < endVal) { |
michael@0 | 91 | aResult.mU.mInt = int64_t(floor(currentVal + 0.5)); // round mid up |
michael@0 | 92 | } else { |
michael@0 | 93 | aResult.mU.mInt = int64_t(ceil(currentVal - 0.5)); // round mid down |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | return NS_OK; |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | } // namespace mozilla |