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 2011 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 | #include "SkBitSet.h" |
michael@0 | 11 | |
michael@0 | 12 | SkBitSet::SkBitSet(int numberOfBits) |
michael@0 | 13 | : fBitData(NULL), fDwordCount(0), fBitCount(numberOfBits) { |
michael@0 | 14 | SkASSERT(numberOfBits > 0); |
michael@0 | 15 | // Round up size to 32-bit boundary. |
michael@0 | 16 | fDwordCount = (numberOfBits + 31) / 32; |
michael@0 | 17 | fBitData.set(malloc(fDwordCount * sizeof(uint32_t))); |
michael@0 | 18 | clearAll(); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | SkBitSet::SkBitSet(const SkBitSet& source) |
michael@0 | 22 | : fBitData(NULL), fDwordCount(0), fBitCount(0) { |
michael@0 | 23 | *this = source; |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | SkBitSet& SkBitSet::operator=(const SkBitSet& rhs) { |
michael@0 | 27 | if (this == &rhs) { |
michael@0 | 28 | return *this; |
michael@0 | 29 | } |
michael@0 | 30 | fBitCount = rhs.fBitCount; |
michael@0 | 31 | fBitData.free(); |
michael@0 | 32 | fDwordCount = rhs.fDwordCount; |
michael@0 | 33 | fBitData.set(malloc(fDwordCount * sizeof(uint32_t))); |
michael@0 | 34 | memcpy(fBitData.get(), rhs.fBitData.get(), fDwordCount * sizeof(uint32_t)); |
michael@0 | 35 | return *this; |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | bool SkBitSet::operator==(const SkBitSet& rhs) { |
michael@0 | 39 | if (fBitCount == rhs.fBitCount) { |
michael@0 | 40 | if (fBitData.get() != NULL) { |
michael@0 | 41 | return (memcmp(fBitData.get(), rhs.fBitData.get(), |
michael@0 | 42 | fDwordCount * sizeof(uint32_t)) == 0); |
michael@0 | 43 | } |
michael@0 | 44 | return true; |
michael@0 | 45 | } |
michael@0 | 46 | return false; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | bool SkBitSet::operator!=(const SkBitSet& rhs) { |
michael@0 | 50 | return !(*this == rhs); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | void SkBitSet::clearAll() { |
michael@0 | 54 | if (fBitData.get() != NULL) { |
michael@0 | 55 | sk_bzero(fBitData.get(), fDwordCount * sizeof(uint32_t)); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | void SkBitSet::setBit(int index, bool value) { |
michael@0 | 60 | uint32_t mask = 1 << (index % 32); |
michael@0 | 61 | if (value) { |
michael@0 | 62 | *(internalGet(index)) |= mask; |
michael@0 | 63 | } else { |
michael@0 | 64 | *(internalGet(index)) &= ~mask; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | bool SkBitSet::isBitSet(int index) const { |
michael@0 | 69 | uint32_t mask = 1 << (index % 32); |
michael@0 | 70 | return 0 != (*internalGet(index) & mask); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | bool SkBitSet::orBits(const SkBitSet& source) { |
michael@0 | 74 | if (fBitCount != source.fBitCount) { |
michael@0 | 75 | return false; |
michael@0 | 76 | } |
michael@0 | 77 | uint32_t* targetBitmap = internalGet(0); |
michael@0 | 78 | uint32_t* sourceBitmap = source.internalGet(0); |
michael@0 | 79 | for (size_t i = 0; i < fDwordCount; ++i) { |
michael@0 | 80 | targetBitmap[i] |= sourceBitmap[i]; |
michael@0 | 81 | } |
michael@0 | 82 | return true; |
michael@0 | 83 | } |