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 SkBuffer_DEFINED |
michael@0 | 11 | #define SkBuffer_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkScalar.h" |
michael@0 | 14 | |
michael@0 | 15 | /** \class SkRBuffer |
michael@0 | 16 | |
michael@0 | 17 | Light weight class for reading data from a memory block. |
michael@0 | 18 | The RBuffer is given the buffer to read from, with either a specified size |
michael@0 | 19 | or no size (in which case no range checking is performed). It is iillegal |
michael@0 | 20 | to attempt to read a value from an empty RBuffer (data == null). |
michael@0 | 21 | */ |
michael@0 | 22 | class SkRBuffer : SkNoncopyable { |
michael@0 | 23 | public: |
michael@0 | 24 | SkRBuffer() : fData(0), fPos(0), fStop(0) {} |
michael@0 | 25 | /** Initialize RBuffer with a data pointer, but no specified length. |
michael@0 | 26 | This signals the RBuffer to not perform range checks during reading. |
michael@0 | 27 | */ |
michael@0 | 28 | SkRBuffer(const void* data) { |
michael@0 | 29 | fData = (const char*)data; |
michael@0 | 30 | fPos = (const char*)data; |
michael@0 | 31 | fStop = 0; // no bounds checking |
michael@0 | 32 | } |
michael@0 | 33 | /** Initialize RBuffer with a data point and length. |
michael@0 | 34 | */ |
michael@0 | 35 | SkRBuffer(const void* data, size_t size) { |
michael@0 | 36 | SkASSERT(data != 0 || size == 0); |
michael@0 | 37 | fData = (const char*)data; |
michael@0 | 38 | fPos = (const char*)data; |
michael@0 | 39 | fStop = (const char*)data + size; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | virtual ~SkRBuffer() { } |
michael@0 | 43 | |
michael@0 | 44 | /** Return the number of bytes that have been read from the beginning |
michael@0 | 45 | of the data pointer. |
michael@0 | 46 | */ |
michael@0 | 47 | size_t pos() const { return fPos - fData; } |
michael@0 | 48 | /** Return the total size of the data pointer. Only defined if the length was |
michael@0 | 49 | specified in the constructor or in a call to reset(). |
michael@0 | 50 | */ |
michael@0 | 51 | size_t size() const { return fStop - fData; } |
michael@0 | 52 | /** Return true if the buffer has read to the end of the data pointer. |
michael@0 | 53 | Only defined if the length was specified in the constructor or in a call |
michael@0 | 54 | to reset(). Always returns true if the length was not specified. |
michael@0 | 55 | */ |
michael@0 | 56 | bool eof() const { return fPos >= fStop; } |
michael@0 | 57 | |
michael@0 | 58 | /** Read the specified number of bytes from the data pointer. If buffer is not |
michael@0 | 59 | null, copy those bytes into buffer. |
michael@0 | 60 | */ |
michael@0 | 61 | virtual bool read(void* buffer, size_t size) { |
michael@0 | 62 | if (size) { |
michael@0 | 63 | this->readNoSizeCheck(buffer, size); |
michael@0 | 64 | } |
michael@0 | 65 | return true; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | const void* skip(size_t size); // return start of skipped data |
michael@0 | 69 | size_t skipToAlign4(); |
michael@0 | 70 | |
michael@0 | 71 | bool readPtr(void** ptr) { return read(ptr, sizeof(void*)); } |
michael@0 | 72 | bool readScalar(SkScalar* x) { return read(x, 4); } |
michael@0 | 73 | bool readU32(uint32_t* x) { return read(x, 4); } |
michael@0 | 74 | bool readS32(int32_t* x) { return read(x, 4); } |
michael@0 | 75 | bool readU16(uint16_t* x) { return read(x, 2); } |
michael@0 | 76 | bool readS16(int16_t* x) { return read(x, 2); } |
michael@0 | 77 | bool readU8(uint8_t* x) { return read(x, 1); } |
michael@0 | 78 | bool readBool(bool* x) { |
michael@0 | 79 | uint8_t u8; |
michael@0 | 80 | if (this->readU8(&u8)) { |
michael@0 | 81 | *x = (u8 != 0); |
michael@0 | 82 | return true; |
michael@0 | 83 | } |
michael@0 | 84 | return false; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | protected: |
michael@0 | 88 | void readNoSizeCheck(void* buffer, size_t size); |
michael@0 | 89 | |
michael@0 | 90 | const char* fData; |
michael@0 | 91 | const char* fPos; |
michael@0 | 92 | const char* fStop; |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | /** \class SkRBufferWithSizeCheck |
michael@0 | 96 | |
michael@0 | 97 | Same as SkRBuffer, except that a size check is performed before the read operation and an |
michael@0 | 98 | error is set if the read operation is attempting to read past the end of the data. |
michael@0 | 99 | */ |
michael@0 | 100 | class SkRBufferWithSizeCheck : public SkRBuffer { |
michael@0 | 101 | public: |
michael@0 | 102 | SkRBufferWithSizeCheck(const void* data, size_t size) : SkRBuffer(data, size), fError(false) {} |
michael@0 | 103 | |
michael@0 | 104 | /** Read the specified number of bytes from the data pointer. If buffer is not |
michael@0 | 105 | null and the number of bytes to read does not overflow this object's data, |
michael@0 | 106 | copy those bytes into buffer. |
michael@0 | 107 | */ |
michael@0 | 108 | virtual bool read(void* buffer, size_t size) SK_OVERRIDE; |
michael@0 | 109 | |
michael@0 | 110 | /** Returns whether or not a read operation attempted to read past the end of the data. |
michael@0 | 111 | */ |
michael@0 | 112 | bool isValid() const { return !fError; } |
michael@0 | 113 | private: |
michael@0 | 114 | bool fError; |
michael@0 | 115 | }; |
michael@0 | 116 | |
michael@0 | 117 | /** \class SkWBuffer |
michael@0 | 118 | |
michael@0 | 119 | Light weight class for writing data to a memory block. |
michael@0 | 120 | The WBuffer is given the buffer to write into, with either a specified size |
michael@0 | 121 | or no size, in which case no range checking is performed. An empty WBuffer |
michael@0 | 122 | is legal, in which case no data is ever written, but the relative pos() |
michael@0 | 123 | is updated. |
michael@0 | 124 | */ |
michael@0 | 125 | class SkWBuffer : SkNoncopyable { |
michael@0 | 126 | public: |
michael@0 | 127 | SkWBuffer() : fData(0), fPos(0), fStop(0) {} |
michael@0 | 128 | SkWBuffer(void* data) { reset(data); } |
michael@0 | 129 | SkWBuffer(void* data, size_t size) { reset(data, size); } |
michael@0 | 130 | |
michael@0 | 131 | void reset(void* data) { |
michael@0 | 132 | fData = (char*)data; |
michael@0 | 133 | fPos = (char*)data; |
michael@0 | 134 | fStop = 0; // no bounds checking |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | void reset(void* data, size_t size) { |
michael@0 | 138 | SkASSERT(data != 0 || size == 0); |
michael@0 | 139 | fData = (char*)data; |
michael@0 | 140 | fPos = (char*)data; |
michael@0 | 141 | fStop = (char*)data + size; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | size_t pos() const { return fPos - fData; } |
michael@0 | 145 | void* skip(size_t size); // return start of skipped data |
michael@0 | 146 | |
michael@0 | 147 | void write(const void* buffer, size_t size) { |
michael@0 | 148 | if (size) { |
michael@0 | 149 | this->writeNoSizeCheck(buffer, size); |
michael@0 | 150 | } |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | size_t padToAlign4(); |
michael@0 | 154 | |
michael@0 | 155 | void writePtr(const void* x) { this->writeNoSizeCheck(&x, sizeof(x)); } |
michael@0 | 156 | void writeScalar(SkScalar x) { this->writeNoSizeCheck(&x, 4); } |
michael@0 | 157 | void write32(int32_t x) { this->writeNoSizeCheck(&x, 4); } |
michael@0 | 158 | void write16(int16_t x) { this->writeNoSizeCheck(&x, 2); } |
michael@0 | 159 | void write8(int8_t x) { this->writeNoSizeCheck(&x, 1); } |
michael@0 | 160 | void writeBool(bool x) { this->write8(x); } |
michael@0 | 161 | |
michael@0 | 162 | private: |
michael@0 | 163 | void writeNoSizeCheck(const void* buffer, size_t size); |
michael@0 | 164 | |
michael@0 | 165 | char* fData; |
michael@0 | 166 | char* fPos; |
michael@0 | 167 | char* fStop; |
michael@0 | 168 | }; |
michael@0 | 169 | |
michael@0 | 170 | #endif |