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: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef GFX_FONT_FEATURES_H |
michael@0 | 8 | #define GFX_FONT_FEATURES_H |
michael@0 | 9 | |
michael@0 | 10 | #include "nsTHashtable.h" |
michael@0 | 11 | #include "nsTArray.h" |
michael@0 | 12 | #include "nsString.h" |
michael@0 | 13 | |
michael@0 | 14 | // An OpenType feature tag and value pair |
michael@0 | 15 | struct gfxFontFeature { |
michael@0 | 16 | uint32_t mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm |
michael@0 | 17 | uint32_t mValue; // 0 = off, 1 = on, larger values may be used as parameters |
michael@0 | 18 | // to features that select among multiple alternatives |
michael@0 | 19 | }; |
michael@0 | 20 | |
michael@0 | 21 | inline bool |
michael@0 | 22 | operator<(const gfxFontFeature& a, const gfxFontFeature& b) |
michael@0 | 23 | { |
michael@0 | 24 | return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue)); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | inline bool |
michael@0 | 28 | operator==(const gfxFontFeature& a, const gfxFontFeature& b) |
michael@0 | 29 | { |
michael@0 | 30 | return (a.mTag == b.mTag) && (a.mValue == b.mValue); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | struct gfxAlternateValue { |
michael@0 | 34 | uint32_t alternate; // constants in gfxFontConstants.h |
michael@0 | 35 | nsString value; // string value to be looked up |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | inline bool |
michael@0 | 39 | operator<(const gfxAlternateValue& a, const gfxAlternateValue& b) |
michael@0 | 40 | { |
michael@0 | 41 | return (a.alternate < b.alternate) || |
michael@0 | 42 | ((a.alternate == b.alternate) && (a.value < b.value)); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | inline bool |
michael@0 | 46 | operator==(const gfxAlternateValue& a, const gfxAlternateValue& b) |
michael@0 | 47 | { |
michael@0 | 48 | return (a.alternate == b.alternate) && (a.value == b.value); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | class gfxFontFeatureValueSet MOZ_FINAL { |
michael@0 | 52 | public: |
michael@0 | 53 | NS_INLINE_DECL_REFCOUNTING(gfxFontFeatureValueSet) |
michael@0 | 54 | |
michael@0 | 55 | gfxFontFeatureValueSet(); |
michael@0 | 56 | |
michael@0 | 57 | struct ValueList { |
michael@0 | 58 | ValueList(const nsAString& aName, const nsTArray<uint32_t>& aSelectors) |
michael@0 | 59 | : name(aName), featureSelectors(aSelectors) |
michael@0 | 60 | {} |
michael@0 | 61 | nsString name; |
michael@0 | 62 | nsTArray<uint32_t> featureSelectors; |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | struct FeatureValues { |
michael@0 | 66 | uint32_t alternate; |
michael@0 | 67 | nsTArray<ValueList> valuelist; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | // returns true if found, false otherwise |
michael@0 | 71 | bool |
michael@0 | 72 | GetFontFeatureValuesFor(const nsAString& aFamily, |
michael@0 | 73 | uint32_t aVariantProperty, |
michael@0 | 74 | const nsAString& aName, |
michael@0 | 75 | nsTArray<uint32_t>& aValues); |
michael@0 | 76 | void |
michael@0 | 77 | AddFontFeatureValues(const nsAString& aFamily, |
michael@0 | 78 | const nsTArray<gfxFontFeatureValueSet::FeatureValues>& aValues); |
michael@0 | 79 | |
michael@0 | 80 | private: |
michael@0 | 81 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 82 | ~gfxFontFeatureValueSet() {} |
michael@0 | 83 | |
michael@0 | 84 | struct FeatureValueHashKey { |
michael@0 | 85 | nsString mFamily; |
michael@0 | 86 | uint32_t mPropVal; |
michael@0 | 87 | nsString mName; |
michael@0 | 88 | |
michael@0 | 89 | FeatureValueHashKey() |
michael@0 | 90 | : mPropVal(0) |
michael@0 | 91 | { } |
michael@0 | 92 | FeatureValueHashKey(const nsAString& aFamily, |
michael@0 | 93 | uint32_t aPropVal, |
michael@0 | 94 | const nsAString& aName) |
michael@0 | 95 | : mFamily(aFamily), mPropVal(aPropVal), mName(aName) |
michael@0 | 96 | { } |
michael@0 | 97 | FeatureValueHashKey(const FeatureValueHashKey& aKey) |
michael@0 | 98 | : mFamily(aKey.mFamily), mPropVal(aKey.mPropVal), mName(aKey.mName) |
michael@0 | 99 | { } |
michael@0 | 100 | }; |
michael@0 | 101 | |
michael@0 | 102 | class FeatureValueHashEntry : public PLDHashEntryHdr { |
michael@0 | 103 | public: |
michael@0 | 104 | typedef const FeatureValueHashKey &KeyType; |
michael@0 | 105 | typedef const FeatureValueHashKey *KeyTypePointer; |
michael@0 | 106 | |
michael@0 | 107 | FeatureValueHashEntry(KeyTypePointer aKey) { } |
michael@0 | 108 | FeatureValueHashEntry(const FeatureValueHashEntry& toCopy) |
michael@0 | 109 | { |
michael@0 | 110 | NS_ERROR("Should not be called"); |
michael@0 | 111 | } |
michael@0 | 112 | ~FeatureValueHashEntry() { } |
michael@0 | 113 | |
michael@0 | 114 | bool KeyEquals(const KeyTypePointer aKey) const; |
michael@0 | 115 | static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } |
michael@0 | 116 | static PLDHashNumber HashKey(const KeyTypePointer aKey); |
michael@0 | 117 | enum { ALLOW_MEMMOVE = true }; |
michael@0 | 118 | |
michael@0 | 119 | FeatureValueHashKey mKey; |
michael@0 | 120 | nsTArray<uint32_t> mValues; |
michael@0 | 121 | }; |
michael@0 | 122 | |
michael@0 | 123 | nsTHashtable<FeatureValueHashEntry> mFontFeatureValues; |
michael@0 | 124 | }; |
michael@0 | 125 | |
michael@0 | 126 | #endif |