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 "SMILStringType.h" |
michael@0 | 7 | #include "nsSMILValue.h" |
michael@0 | 8 | #include "nsDebug.h" |
michael@0 | 9 | #include "nsString.h" |
michael@0 | 10 | |
michael@0 | 11 | namespace mozilla { |
michael@0 | 12 | |
michael@0 | 13 | void |
michael@0 | 14 | SMILStringType::Init(nsSMILValue& aValue) const |
michael@0 | 15 | { |
michael@0 | 16 | NS_PRECONDITION(aValue.IsNull(), "Unexpected value type"); |
michael@0 | 17 | aValue.mU.mPtr = new nsString(); |
michael@0 | 18 | aValue.mType = this; |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | void |
michael@0 | 22 | SMILStringType::Destroy(nsSMILValue& aValue) const |
michael@0 | 23 | { |
michael@0 | 24 | NS_PRECONDITION(aValue.mType == this, "Unexpected SMIL value"); |
michael@0 | 25 | delete static_cast<nsAString*>(aValue.mU.mPtr); |
michael@0 | 26 | aValue.mU.mPtr = nullptr; |
michael@0 | 27 | aValue.mType = nsSMILNullType::Singleton(); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | nsresult |
michael@0 | 31 | SMILStringType::Assign(nsSMILValue& aDest, const nsSMILValue& aSrc) const |
michael@0 | 32 | { |
michael@0 | 33 | NS_PRECONDITION(aDest.mType == aSrc.mType, "Incompatible SMIL types"); |
michael@0 | 34 | NS_PRECONDITION(aDest.mType == this, "Unexpected SMIL value"); |
michael@0 | 35 | |
michael@0 | 36 | const nsAString* src = static_cast<const nsAString*>(aSrc.mU.mPtr); |
michael@0 | 37 | nsAString* dst = static_cast<nsAString*>(aDest.mU.mPtr); |
michael@0 | 38 | *dst = *src; |
michael@0 | 39 | return NS_OK; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | bool |
michael@0 | 43 | SMILStringType::IsEqual(const nsSMILValue& aLeft, |
michael@0 | 44 | const nsSMILValue& aRight) const |
michael@0 | 45 | { |
michael@0 | 46 | NS_PRECONDITION(aLeft.mType == aRight.mType, "Incompatible SMIL types"); |
michael@0 | 47 | NS_PRECONDITION(aLeft.mType == this, "Unexpected type for SMIL value"); |
michael@0 | 48 | |
michael@0 | 49 | const nsAString* leftString = |
michael@0 | 50 | static_cast<const nsAString*>(aLeft.mU.mPtr); |
michael@0 | 51 | const nsAString* rightString = |
michael@0 | 52 | static_cast<nsAString*>(aRight.mU.mPtr); |
michael@0 | 53 | return *leftString == *rightString; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | nsresult |
michael@0 | 57 | SMILStringType::Add(nsSMILValue& aDest, const nsSMILValue& aValueToAdd, |
michael@0 | 58 | uint32_t aCount) const |
michael@0 | 59 | { |
michael@0 | 60 | NS_PRECONDITION(aValueToAdd.mType == aDest.mType, |
michael@0 | 61 | "Trying to add invalid types"); |
michael@0 | 62 | NS_PRECONDITION(aValueToAdd.mType == this, "Unexpected source type"); |
michael@0 | 63 | return NS_ERROR_FAILURE; // string values can't be added to each other |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | nsresult |
michael@0 | 67 | SMILStringType::ComputeDistance(const nsSMILValue& aFrom, |
michael@0 | 68 | const nsSMILValue& aTo, |
michael@0 | 69 | double& aDistance) const |
michael@0 | 70 | { |
michael@0 | 71 | NS_PRECONDITION(aFrom.mType == aTo.mType,"Trying to compare different types"); |
michael@0 | 72 | NS_PRECONDITION(aFrom.mType == this, "Unexpected source type"); |
michael@0 | 73 | return NS_ERROR_FAILURE; // there is no concept of distance between string values |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | nsresult |
michael@0 | 77 | SMILStringType::Interpolate(const nsSMILValue& aStartVal, |
michael@0 | 78 | const nsSMILValue& aEndVal, |
michael@0 | 79 | double aUnitDistance, |
michael@0 | 80 | nsSMILValue& aResult) const |
michael@0 | 81 | { |
michael@0 | 82 | NS_PRECONDITION(aStartVal.mType == aEndVal.mType, |
michael@0 | 83 | "Trying to interpolate different types"); |
michael@0 | 84 | NS_PRECONDITION(aStartVal.mType == this, |
michael@0 | 85 | "Unexpected types for interpolation"); |
michael@0 | 86 | NS_PRECONDITION(aResult.mType == this, "Unexpected result type"); |
michael@0 | 87 | return NS_ERROR_FAILURE; // string values do not interpolate |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | } // namespace mozilla |