Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2010 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | |
michael@0 | 11 | #ifndef GrTextStrike_impl_DEFINED |
michael@0 | 12 | #define GrTextStrike_impl_DEFINED |
michael@0 | 13 | |
michael@0 | 14 | class GrFontCache::Key { |
michael@0 | 15 | public: |
michael@0 | 16 | explicit Key(const GrKey* fontScalarKey) { |
michael@0 | 17 | fFontScalerKey = fontScalarKey; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | intptr_t getHash() const { return fFontScalerKey->getHash(); } |
michael@0 | 21 | |
michael@0 | 22 | static bool LessThan(const GrTextStrike& strike, const Key& key) { |
michael@0 | 23 | return *strike.getFontScalerKey() < *key.fFontScalerKey; |
michael@0 | 24 | } |
michael@0 | 25 | static bool Equals(const GrTextStrike& strike, const Key& key) { |
michael@0 | 26 | return *strike.getFontScalerKey() == *key.fFontScalerKey; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | private: |
michael@0 | 30 | const GrKey* fFontScalerKey; |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | void GrFontCache::detachStrikeFromList(GrTextStrike* strike) { |
michael@0 | 34 | if (strike->fPrev) { |
michael@0 | 35 | SkASSERT(fHead != strike); |
michael@0 | 36 | strike->fPrev->fNext = strike->fNext; |
michael@0 | 37 | } else { |
michael@0 | 38 | SkASSERT(fHead == strike); |
michael@0 | 39 | fHead = strike->fNext; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | if (strike->fNext) { |
michael@0 | 43 | SkASSERT(fTail != strike); |
michael@0 | 44 | strike->fNext->fPrev = strike->fPrev; |
michael@0 | 45 | } else { |
michael@0 | 46 | SkASSERT(fTail == strike); |
michael@0 | 47 | fTail = strike->fPrev; |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | GrTextStrike* GrFontCache::getStrike(GrFontScaler* scaler, bool useDistanceField) { |
michael@0 | 52 | this->validate(); |
michael@0 | 53 | |
michael@0 | 54 | const Key key(scaler->getKey()); |
michael@0 | 55 | GrTextStrike* strike = fCache.find(key); |
michael@0 | 56 | if (NULL == strike) { |
michael@0 | 57 | strike = this->generateStrike(scaler, key); |
michael@0 | 58 | } else if (strike->fPrev) { |
michael@0 | 59 | // Need to put the strike at the head of its dllist, since that is how |
michael@0 | 60 | // we age the strikes for purging (we purge from the back of the list |
michael@0 | 61 | this->detachStrikeFromList(strike); |
michael@0 | 62 | // attach at the head |
michael@0 | 63 | fHead->fPrev = strike; |
michael@0 | 64 | strike->fNext = fHead; |
michael@0 | 65 | strike->fPrev = NULL; |
michael@0 | 66 | fHead = strike; |
michael@0 | 67 | } |
michael@0 | 68 | strike->fUseDistanceField = useDistanceField; |
michael@0 | 69 | this->validate(); |
michael@0 | 70 | return strike; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * This Key just wraps a glyphID, and matches the protocol need for |
michael@0 | 77 | * GrTHashTable |
michael@0 | 78 | */ |
michael@0 | 79 | class GrTextStrike::Key { |
michael@0 | 80 | public: |
michael@0 | 81 | Key(GrGlyph::PackedID id) : fPackedID(id) {} |
michael@0 | 82 | |
michael@0 | 83 | uint32_t getHash() const { return fPackedID; } |
michael@0 | 84 | |
michael@0 | 85 | static bool LessThan(const GrGlyph& glyph, const Key& key) { |
michael@0 | 86 | return glyph.fPackedID < key.fPackedID; |
michael@0 | 87 | } |
michael@0 | 88 | static bool Equals(const GrGlyph& glyph, const Key& key) { |
michael@0 | 89 | return glyph.fPackedID == key.fPackedID; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | private: |
michael@0 | 93 | GrGlyph::PackedID fPackedID; |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | GrGlyph* GrTextStrike::getGlyph(GrGlyph::PackedID packed, |
michael@0 | 97 | GrFontScaler* scaler) { |
michael@0 | 98 | GrGlyph* glyph = fCache.find(packed); |
michael@0 | 99 | if (NULL == glyph) { |
michael@0 | 100 | glyph = this->generateGlyph(packed, scaler); |
michael@0 | 101 | } |
michael@0 | 102 | return glyph; |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | #endif |