gfx/thebes/gfxFontFeatures.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.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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 "gfxFontFeatures.h"
michael@0 7 #include "nsUnicharUtils.h"
michael@0 8 #include "nsHashKeys.h"
michael@0 9
michael@0 10 using namespace mozilla;
michael@0 11
michael@0 12 gfxFontFeatureValueSet::gfxFontFeatureValueSet()
michael@0 13 : mFontFeatureValues(10)
michael@0 14 {
michael@0 15 }
michael@0 16
michael@0 17 bool
michael@0 18 gfxFontFeatureValueSet::GetFontFeatureValuesFor(const nsAString& aFamily,
michael@0 19 uint32_t aVariantProperty,
michael@0 20 const nsAString& aName,
michael@0 21 nsTArray<uint32_t>& aValues)
michael@0 22 {
michael@0 23 nsAutoString family(aFamily), name(aName);
michael@0 24 ToLowerCase(family);
michael@0 25 ToLowerCase(name);
michael@0 26 FeatureValueHashKey key(family, aVariantProperty, name);
michael@0 27
michael@0 28 aValues.Clear();
michael@0 29 FeatureValueHashEntry *entry = mFontFeatureValues.GetEntry(key);
michael@0 30 if (entry) {
michael@0 31 NS_ASSERTION(entry->mValues.Length() > 0,
michael@0 32 "null array of font feature values");
michael@0 33 aValues.AppendElements(entry->mValues);
michael@0 34 return true;
michael@0 35 }
michael@0 36
michael@0 37 return false;
michael@0 38 }
michael@0 39
michael@0 40
michael@0 41 void
michael@0 42 gfxFontFeatureValueSet::AddFontFeatureValues(const nsAString& aFamily,
michael@0 43 const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues)
michael@0 44 {
michael@0 45 nsAutoString family(aFamily);
michael@0 46 ToLowerCase(family);
michael@0 47
michael@0 48 uint32_t i, numFeatureValues = aValues.Length();
michael@0 49 for (i = 0; i < numFeatureValues; i++) {
michael@0 50 const FeatureValues& fv = aValues.ElementAt(i);
michael@0 51 uint32_t alternate = fv.alternate;
michael@0 52 uint32_t j, numValues = fv.valuelist.Length();
michael@0 53 for (j = 0; j < numValues; j++) {
michael@0 54 const ValueList& v = fv.valuelist.ElementAt(j);
michael@0 55 nsAutoString name(v.name);
michael@0 56 ToLowerCase(name);
michael@0 57 FeatureValueHashKey key(family, alternate, name);
michael@0 58 FeatureValueHashEntry *entry = mFontFeatureValues.PutEntry(key);
michael@0 59 entry->mKey = key;
michael@0 60 entry->mValues = v.featureSelectors;
michael@0 61 }
michael@0 62 }
michael@0 63 }
michael@0 64
michael@0 65 bool
michael@0 66 gfxFontFeatureValueSet::FeatureValueHashEntry::KeyEquals(
michael@0 67 const KeyTypePointer aKey) const
michael@0 68 {
michael@0 69 return aKey->mPropVal == mKey.mPropVal &&
michael@0 70 aKey->mFamily.Equals(mKey.mFamily) &&
michael@0 71 aKey->mName.Equals(mKey.mName);
michael@0 72 }
michael@0 73
michael@0 74 PLDHashNumber
michael@0 75 gfxFontFeatureValueSet::FeatureValueHashEntry::HashKey(
michael@0 76 const KeyTypePointer aKey)
michael@0 77 {
michael@0 78 return HashString(aKey->mFamily) + HashString(aKey->mName) +
michael@0 79 aKey->mPropVal * uint32_t(0xdeadbeef);
michael@0 80 }
michael@0 81

mercurial