dom/smil/SMILStringType.cpp

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.

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

mercurial