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 2006 The Android Open Source Project |
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 | #ifndef SkEndian_DEFINED |
michael@0 | 11 | #define SkEndian_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkTypes.h" |
michael@0 | 14 | |
michael@0 | 15 | /** \file SkEndian.h |
michael@0 | 16 | |
michael@0 | 17 | Macros and helper functions for handling 16 and 32 bit values in |
michael@0 | 18 | big and little endian formats. |
michael@0 | 19 | */ |
michael@0 | 20 | |
michael@0 | 21 | #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) |
michael@0 | 22 | #error "can't have both LENDIAN and BENDIAN defined" |
michael@0 | 23 | #endif |
michael@0 | 24 | |
michael@0 | 25 | #if !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) |
michael@0 | 26 | #error "need either LENDIAN or BENDIAN defined" |
michael@0 | 27 | #endif |
michael@0 | 28 | |
michael@0 | 29 | /** Swap the two bytes in the low 16bits of the parameters. |
michael@0 | 30 | e.g. 0x1234 -> 0x3412 |
michael@0 | 31 | */ |
michael@0 | 32 | static inline uint16_t SkEndianSwap16(U16CPU value) { |
michael@0 | 33 | SkASSERT(value == (uint16_t)value); |
michael@0 | 34 | return static_cast<uint16_t>((value >> 8) | (value << 8)); |
michael@0 | 35 | } |
michael@0 | 36 | template<uint16_t N> struct SkTEndianSwap16 { |
michael@0 | 37 | static const uint16_t value = static_cast<uint16_t>((N >> 8) | ((N & 0xFF) << 8)); |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | /** Vector version of SkEndianSwap16(), which swaps the |
michael@0 | 41 | low two bytes of each value in the array. |
michael@0 | 42 | */ |
michael@0 | 43 | static inline void SkEndianSwap16s(uint16_t array[], int count) { |
michael@0 | 44 | SkASSERT(count == 0 || array != NULL); |
michael@0 | 45 | |
michael@0 | 46 | while (--count >= 0) { |
michael@0 | 47 | *array = SkEndianSwap16(*array); |
michael@0 | 48 | array += 1; |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | /** Reverse all 4 bytes in a 32bit value. |
michael@0 | 53 | e.g. 0x12345678 -> 0x78563412 |
michael@0 | 54 | */ |
michael@0 | 55 | static inline uint32_t SkEndianSwap32(uint32_t value) { |
michael@0 | 56 | return ((value & 0xFF) << 24) | |
michael@0 | 57 | ((value & 0xFF00) << 8) | |
michael@0 | 58 | ((value & 0xFF0000) >> 8) | |
michael@0 | 59 | (value >> 24); |
michael@0 | 60 | } |
michael@0 | 61 | template<uint32_t N> struct SkTEndianSwap32 { |
michael@0 | 62 | static const uint32_t value = ((N & 0xFF) << 24) | |
michael@0 | 63 | ((N & 0xFF00) << 8) | |
michael@0 | 64 | ((N & 0xFF0000) >> 8) | |
michael@0 | 65 | (N >> 24); |
michael@0 | 66 | }; |
michael@0 | 67 | |
michael@0 | 68 | /** Vector version of SkEndianSwap32(), which swaps the |
michael@0 | 69 | bytes of each value in the array. |
michael@0 | 70 | */ |
michael@0 | 71 | static inline void SkEndianSwap32s(uint32_t array[], int count) { |
michael@0 | 72 | SkASSERT(count == 0 || array != NULL); |
michael@0 | 73 | |
michael@0 | 74 | while (--count >= 0) { |
michael@0 | 75 | *array = SkEndianSwap32(*array); |
michael@0 | 76 | array += 1; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | /** Reverse all 8 bytes in a 64bit value. |
michael@0 | 81 | e.g. 0x1122334455667788 -> 0x8877665544332211 |
michael@0 | 82 | */ |
michael@0 | 83 | static inline uint64_t SkEndianSwap64(uint64_t value) { |
michael@0 | 84 | return (((value & 0x00000000000000FFULL) << (8*7)) | |
michael@0 | 85 | ((value & 0x000000000000FF00ULL) << (8*5)) | |
michael@0 | 86 | ((value & 0x0000000000FF0000ULL) << (8*3)) | |
michael@0 | 87 | ((value & 0x00000000FF000000ULL) << (8*1)) | |
michael@0 | 88 | ((value & 0x000000FF00000000ULL) >> (8*1)) | |
michael@0 | 89 | ((value & 0x0000FF0000000000ULL) >> (8*3)) | |
michael@0 | 90 | ((value & 0x00FF000000000000ULL) >> (8*5)) | |
michael@0 | 91 | ((value) >> (8*7))); |
michael@0 | 92 | } |
michael@0 | 93 | template<uint64_t N> struct SkTEndianSwap64 { |
michael@0 | 94 | static const uint64_t value = (((N & 0x00000000000000FFULL) << (8*7)) | |
michael@0 | 95 | ((N & 0x000000000000FF00ULL) << (8*5)) | |
michael@0 | 96 | ((N & 0x0000000000FF0000ULL) << (8*3)) | |
michael@0 | 97 | ((N & 0x00000000FF000000ULL) << (8*1)) | |
michael@0 | 98 | ((N & 0x000000FF00000000ULL) >> (8*1)) | |
michael@0 | 99 | ((N & 0x0000FF0000000000ULL) >> (8*3)) | |
michael@0 | 100 | ((N & 0x00FF000000000000ULL) >> (8*5)) | |
michael@0 | 101 | ((N) >> (8*7))); |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | /** Vector version of SkEndianSwap64(), which swaps the |
michael@0 | 105 | bytes of each value in the array. |
michael@0 | 106 | */ |
michael@0 | 107 | static inline void SkEndianSwap64s(uint64_t array[], int count) { |
michael@0 | 108 | SkASSERT(count == 0 || array != NULL); |
michael@0 | 109 | |
michael@0 | 110 | while (--count >= 0) { |
michael@0 | 111 | *array = SkEndianSwap64(*array); |
michael@0 | 112 | array += 1; |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | #ifdef SK_CPU_LENDIAN |
michael@0 | 117 | #define SkEndian_SwapBE16(n) SkEndianSwap16(n) |
michael@0 | 118 | #define SkEndian_SwapBE32(n) SkEndianSwap32(n) |
michael@0 | 119 | #define SkEndian_SwapBE64(n) SkEndianSwap64(n) |
michael@0 | 120 | #define SkEndian_SwapLE16(n) (n) |
michael@0 | 121 | #define SkEndian_SwapLE32(n) (n) |
michael@0 | 122 | #define SkEndian_SwapLE64(n) (n) |
michael@0 | 123 | |
michael@0 | 124 | #define SkTEndian_SwapBE16(n) SkTEndianSwap16<n>::value |
michael@0 | 125 | #define SkTEndian_SwapBE32(n) SkTEndianSwap32<n>::value |
michael@0 | 126 | #define SkTEndian_SwapBE64(n) SkTEndianSwap64<n>::value |
michael@0 | 127 | #define SkTEndian_SwapLE16(n) (n) |
michael@0 | 128 | #define SkTEndian_SwapLE32(n) (n) |
michael@0 | 129 | #define SkTEndian_SwapLE64(n) (n) |
michael@0 | 130 | #else // SK_CPU_BENDIAN |
michael@0 | 131 | #define SkEndian_SwapBE16(n) (n) |
michael@0 | 132 | #define SkEndian_SwapBE32(n) (n) |
michael@0 | 133 | #define SkEndian_SwapBE64(n) (n) |
michael@0 | 134 | #define SkEndian_SwapLE16(n) SkEndianSwap16(n) |
michael@0 | 135 | #define SkEndian_SwapLE32(n) SkEndianSwap32(n) |
michael@0 | 136 | #define SkEndian_SwapLE64(n) SkEndianSwap64(n) |
michael@0 | 137 | |
michael@0 | 138 | #define SkTEndian_SwapBE16(n) (n) |
michael@0 | 139 | #define SkTEndian_SwapBE32(n) (n) |
michael@0 | 140 | #define SkTEndian_SwapBE64(n) (n) |
michael@0 | 141 | #define SkTEndian_SwapLE16(n) SkTEndianSwap16<n>::value |
michael@0 | 142 | #define SkTEndian_SwapLE32(n) SkTEndianSwap32<n>::value |
michael@0 | 143 | #define SkTEndian_SwapLE64(n) SkTEndianSwap64<n>::value |
michael@0 | 144 | #endif |
michael@0 | 145 | |
michael@0 | 146 | // When a bytestream is embedded in a 32-bit word, how far we need to |
michael@0 | 147 | // shift the word to extract each byte from the low 8 bits by anding with 0xff. |
michael@0 | 148 | #ifdef SK_CPU_LENDIAN |
michael@0 | 149 | #define SkEndian_Byte0Shift 0 |
michael@0 | 150 | #define SkEndian_Byte1Shift 8 |
michael@0 | 151 | #define SkEndian_Byte2Shift 16 |
michael@0 | 152 | #define SkEndian_Byte3Shift 24 |
michael@0 | 153 | #else // SK_CPU_BENDIAN |
michael@0 | 154 | #define SkEndian_Byte0Shift 24 |
michael@0 | 155 | #define SkEndian_Byte1Shift 16 |
michael@0 | 156 | #define SkEndian_Byte2Shift 8 |
michael@0 | 157 | #define SkEndian_Byte3Shift 0 |
michael@0 | 158 | #endif |
michael@0 | 159 | |
michael@0 | 160 | |
michael@0 | 161 | #if defined(SK_UINT8_BITFIELD_LENDIAN) && defined(SK_UINT8_BITFIELD_BENDIAN) |
michael@0 | 162 | #error "can't have both bitfield LENDIAN and BENDIAN defined" |
michael@0 | 163 | #endif |
michael@0 | 164 | |
michael@0 | 165 | #if !defined(SK_UINT8_BITFIELD_LENDIAN) && !defined(SK_UINT8_BITFIELD_BENDIAN) |
michael@0 | 166 | #ifdef SK_CPU_LENDIAN |
michael@0 | 167 | #define SK_UINT8_BITFIELD_LENDIAN |
michael@0 | 168 | #else |
michael@0 | 169 | #define SK_UINT8_BITFIELD_BENDIAN |
michael@0 | 170 | #endif |
michael@0 | 171 | #endif |
michael@0 | 172 | |
michael@0 | 173 | #ifdef SK_UINT8_BITFIELD_LENDIAN |
michael@0 | 174 | #define SK_UINT8_BITFIELD(f0, f1, f2, f3, f4, f5, f6, f7) \ |
michael@0 | 175 | SK_OT_BYTE f0 : 1; \ |
michael@0 | 176 | SK_OT_BYTE f1 : 1; \ |
michael@0 | 177 | SK_OT_BYTE f2 : 1; \ |
michael@0 | 178 | SK_OT_BYTE f3 : 1; \ |
michael@0 | 179 | SK_OT_BYTE f4 : 1; \ |
michael@0 | 180 | SK_OT_BYTE f5 : 1; \ |
michael@0 | 181 | SK_OT_BYTE f6 : 1; \ |
michael@0 | 182 | SK_OT_BYTE f7 : 1; |
michael@0 | 183 | #else |
michael@0 | 184 | #define SK_UINT8_BITFIELD(f0, f1, f2, f3, f4, f5, f6, f7) \ |
michael@0 | 185 | SK_OT_BYTE f7 : 1; \ |
michael@0 | 186 | SK_OT_BYTE f6 : 1; \ |
michael@0 | 187 | SK_OT_BYTE f5 : 1; \ |
michael@0 | 188 | SK_OT_BYTE f4 : 1; \ |
michael@0 | 189 | SK_OT_BYTE f3 : 1; \ |
michael@0 | 190 | SK_OT_BYTE f2 : 1; \ |
michael@0 | 191 | SK_OT_BYTE f1 : 1; \ |
michael@0 | 192 | SK_OT_BYTE f0 : 1; |
michael@0 | 193 | #endif |
michael@0 | 194 | |
michael@0 | 195 | #endif |