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 2008 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 SkReader32_DEFINED |
michael@0 | 11 | #define SkReader32_DEFINED |
michael@0 | 12 | |
michael@0 | 13 | #include "SkMatrix.h" |
michael@0 | 14 | #include "SkPath.h" |
michael@0 | 15 | #include "SkRegion.h" |
michael@0 | 16 | #include "SkRRect.h" |
michael@0 | 17 | #include "SkScalar.h" |
michael@0 | 18 | |
michael@0 | 19 | class SkString; |
michael@0 | 20 | |
michael@0 | 21 | class SkReader32 : SkNoncopyable { |
michael@0 | 22 | public: |
michael@0 | 23 | SkReader32() : fCurr(NULL), fStop(NULL), fBase(NULL) {} |
michael@0 | 24 | SkReader32(const void* data, size_t size) { |
michael@0 | 25 | this->setMemory(data, size); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | void setMemory(const void* data, size_t size) { |
michael@0 | 29 | SkASSERT(ptr_align_4(data)); |
michael@0 | 30 | SkASSERT(SkAlign4(size) == size); |
michael@0 | 31 | |
michael@0 | 32 | fBase = fCurr = (const char*)data; |
michael@0 | 33 | fStop = (const char*)data + size; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | uint32_t size() const { return SkToU32(fStop - fBase); } |
michael@0 | 37 | uint32_t offset() const { return SkToU32(fCurr - fBase); } |
michael@0 | 38 | bool eof() const { return fCurr >= fStop; } |
michael@0 | 39 | const void* base() const { return fBase; } |
michael@0 | 40 | const void* peek() const { return fCurr; } |
michael@0 | 41 | |
michael@0 | 42 | uint32_t available() const { return SkToU32(fStop - fCurr); } |
michael@0 | 43 | bool isAvailable(uint32_t size) const { return fCurr + size <= fStop; } |
michael@0 | 44 | |
michael@0 | 45 | void rewind() { fCurr = fBase; } |
michael@0 | 46 | |
michael@0 | 47 | void setOffset(size_t offset) { |
michael@0 | 48 | SkASSERT(SkAlign4(offset) == offset); |
michael@0 | 49 | SkASSERT(offset <= this->size()); |
michael@0 | 50 | fCurr = fBase + offset; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | bool readBool() { return this->readInt() != 0; } |
michael@0 | 54 | |
michael@0 | 55 | int32_t readInt() { |
michael@0 | 56 | SkASSERT(ptr_align_4(fCurr)); |
michael@0 | 57 | int32_t value = *(const int32_t*)fCurr; |
michael@0 | 58 | fCurr += sizeof(value); |
michael@0 | 59 | SkASSERT(fCurr <= fStop); |
michael@0 | 60 | return value; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | void* readPtr() { |
michael@0 | 64 | void* ptr; |
michael@0 | 65 | // we presume this "if" is resolved at compile-time |
michael@0 | 66 | if (4 == sizeof(void*)) { |
michael@0 | 67 | ptr = *(void**)fCurr; |
michael@0 | 68 | } else { |
michael@0 | 69 | memcpy(&ptr, fCurr, sizeof(void*)); |
michael@0 | 70 | } |
michael@0 | 71 | fCurr += sizeof(void*); |
michael@0 | 72 | return ptr; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | SkScalar readScalar() { |
michael@0 | 76 | SkASSERT(ptr_align_4(fCurr)); |
michael@0 | 77 | SkScalar value = *(const SkScalar*)fCurr; |
michael@0 | 78 | fCurr += sizeof(value); |
michael@0 | 79 | SkASSERT(fCurr <= fStop); |
michael@0 | 80 | return value; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | const void* skip(size_t size) { |
michael@0 | 84 | SkASSERT(ptr_align_4(fCurr)); |
michael@0 | 85 | const void* addr = fCurr; |
michael@0 | 86 | fCurr += SkAlign4(size); |
michael@0 | 87 | SkASSERT(fCurr <= fStop); |
michael@0 | 88 | return addr; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | template <typename T> const T& skipT() { |
michael@0 | 92 | SkASSERT(SkAlign4(sizeof(T)) == sizeof(T)); |
michael@0 | 93 | return *(const T*)this->skip(sizeof(T)); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | void read(void* dst, size_t size) { |
michael@0 | 97 | SkASSERT(0 == size || dst != NULL); |
michael@0 | 98 | SkASSERT(ptr_align_4(fCurr)); |
michael@0 | 99 | memcpy(dst, fCurr, size); |
michael@0 | 100 | fCurr += SkAlign4(size); |
michael@0 | 101 | SkASSERT(fCurr <= fStop); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | uint8_t readU8() { return (uint8_t)this->readInt(); } |
michael@0 | 105 | uint16_t readU16() { return (uint16_t)this->readInt(); } |
michael@0 | 106 | int32_t readS32() { return this->readInt(); } |
michael@0 | 107 | uint32_t readU32() { return this->readInt(); } |
michael@0 | 108 | |
michael@0 | 109 | bool readPath(SkPath* path) { |
michael@0 | 110 | return readObjectFromMemory(path); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | bool readMatrix(SkMatrix* matrix) { |
michael@0 | 114 | return readObjectFromMemory(matrix); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | bool readRRect(SkRRect* rrect) { |
michael@0 | 118 | return readObjectFromMemory(rrect); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | bool readRegion(SkRegion* rgn) { |
michael@0 | 122 | return readObjectFromMemory(rgn); |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | /** |
michael@0 | 126 | * Read the length of a string (written by SkWriter32::writeString) into |
michael@0 | 127 | * len (if len is not NULL) and return the null-ternimated address of the |
michael@0 | 128 | * string within the reader's buffer. |
michael@0 | 129 | */ |
michael@0 | 130 | const char* readString(size_t* len = NULL); |
michael@0 | 131 | |
michael@0 | 132 | /** |
michael@0 | 133 | * Read the string (written by SkWriter32::writeString) and return it in |
michael@0 | 134 | * copy (if copy is not null). Return the length of the string. |
michael@0 | 135 | */ |
michael@0 | 136 | size_t readIntoString(SkString* copy); |
michael@0 | 137 | |
michael@0 | 138 | private: |
michael@0 | 139 | template <typename T> bool readObjectFromMemory(T* obj) { |
michael@0 | 140 | size_t size = obj->readFromMemory(this->peek(), this->available()); |
michael@0 | 141 | // If readFromMemory() fails (which means that available() was too small), it returns 0 |
michael@0 | 142 | bool success = (size > 0) && (size <= this->available()) && (SkAlign4(size) == size); |
michael@0 | 143 | // In case of failure, we want to skip to the end |
michael@0 | 144 | (void)this->skip(success ? size : this->available()); |
michael@0 | 145 | return success; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | // these are always 4-byte aligned |
michael@0 | 149 | const char* fCurr; // current position within buffer |
michael@0 | 150 | const char* fStop; // end of buffer |
michael@0 | 151 | const char* fBase; // beginning of buffer |
michael@0 | 152 | |
michael@0 | 153 | #ifdef SK_DEBUG |
michael@0 | 154 | static bool ptr_align_4(const void* ptr) { |
michael@0 | 155 | return (((const char*)ptr - (const char*)NULL) & 3) == 0; |
michael@0 | 156 | } |
michael@0 | 157 | #endif |
michael@0 | 158 | }; |
michael@0 | 159 | |
michael@0 | 160 | #endif |