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 | #ifndef SkReadBuffer_DEFINED |
michael@0 | 10 | #define SkReadBuffer_DEFINED |
michael@0 | 11 | |
michael@0 | 12 | #include "SkBitmapHeap.h" |
michael@0 | 13 | #include "SkColorFilter.h" |
michael@0 | 14 | #include "SkData.h" |
michael@0 | 15 | #include "SkDrawLooper.h" |
michael@0 | 16 | #include "SkImageFilter.h" |
michael@0 | 17 | #include "SkMaskFilter.h" |
michael@0 | 18 | #include "SkPath.h" |
michael@0 | 19 | #include "SkPathEffect.h" |
michael@0 | 20 | #include "SkPicture.h" |
michael@0 | 21 | #include "SkPixelRef.h" |
michael@0 | 22 | #include "SkRasterizer.h" |
michael@0 | 23 | #include "SkReadBuffer.h" |
michael@0 | 24 | #include "SkReader32.h" |
michael@0 | 25 | #include "SkRefCnt.h" |
michael@0 | 26 | #include "SkShader.h" |
michael@0 | 27 | #include "SkUnitMapper.h" |
michael@0 | 28 | #include "SkWriteBuffer.h" |
michael@0 | 29 | #include "SkXfermode.h" |
michael@0 | 30 | |
michael@0 | 31 | class SkBitmap; |
michael@0 | 32 | |
michael@0 | 33 | #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC) |
michael@0 | 34 | #define DEBUG_NON_DETERMINISTIC_ASSERT |
michael@0 | 35 | #endif |
michael@0 | 36 | |
michael@0 | 37 | class SkReadBuffer { |
michael@0 | 38 | public: |
michael@0 | 39 | SkReadBuffer(); |
michael@0 | 40 | SkReadBuffer(const void* data, size_t size); |
michael@0 | 41 | SkReadBuffer(SkStream* stream); |
michael@0 | 42 | virtual ~SkReadBuffer(); |
michael@0 | 43 | |
michael@0 | 44 | enum Flags { |
michael@0 | 45 | kCrossProcess_Flag = 1 << 0, |
michael@0 | 46 | kScalarIsFloat_Flag = 1 << 1, |
michael@0 | 47 | kPtrIs64Bit_Flag = 1 << 2, |
michael@0 | 48 | kValidation_Flag = 1 << 3, |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | void setFlags(uint32_t flags) { fFlags = flags; } |
michael@0 | 52 | uint32_t getFlags() const { return fFlags; } |
michael@0 | 53 | |
michael@0 | 54 | bool isCrossProcess() const { |
michael@0 | 55 | return this->isValidating() || SkToBool(fFlags & kCrossProcess_Flag); |
michael@0 | 56 | } |
michael@0 | 57 | bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); } |
michael@0 | 58 | bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); } |
michael@0 | 59 | bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); } |
michael@0 | 60 | |
michael@0 | 61 | SkReader32* getReader32() { return &fReader; } |
michael@0 | 62 | |
michael@0 | 63 | uint32_t size() { return fReader.size(); } |
michael@0 | 64 | uint32_t offset() { return fReader.offset(); } |
michael@0 | 65 | bool eof() { return fReader.eof(); } |
michael@0 | 66 | const void* skip(size_t size) { return fReader.skip(size); } |
michael@0 | 67 | |
michael@0 | 68 | // primitives |
michael@0 | 69 | virtual bool readBool(); |
michael@0 | 70 | virtual SkColor readColor(); |
michael@0 | 71 | virtual SkFixed readFixed(); |
michael@0 | 72 | virtual int32_t readInt(); |
michael@0 | 73 | virtual SkScalar readScalar(); |
michael@0 | 74 | virtual uint32_t readUInt(); |
michael@0 | 75 | virtual int32_t read32(); |
michael@0 | 76 | |
michael@0 | 77 | void* readFunctionPtr() { |
michael@0 | 78 | void* ptr; |
michael@0 | 79 | this->readByteArray(&ptr, sizeof(ptr)); |
michael@0 | 80 | return ptr; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | // strings -- the caller is responsible for freeing the string contents |
michael@0 | 84 | virtual void readString(SkString* string); |
michael@0 | 85 | virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding); |
michael@0 | 86 | |
michael@0 | 87 | // common data structures |
michael@0 | 88 | virtual void readPoint(SkPoint* point); |
michael@0 | 89 | SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; } |
michael@0 | 90 | virtual void readMatrix(SkMatrix* matrix); |
michael@0 | 91 | virtual void readIRect(SkIRect* rect); |
michael@0 | 92 | virtual void readRect(SkRect* rect); |
michael@0 | 93 | virtual void readRegion(SkRegion* region); |
michael@0 | 94 | virtual void readPath(SkPath* path); |
michael@0 | 95 | void readPaint(SkPaint* paint) { paint->unflatten(*this); } |
michael@0 | 96 | |
michael@0 | 97 | virtual SkFlattenable* readFlattenable(SkFlattenable::Type); |
michael@0 | 98 | template <typename T> T* readFlattenable() { |
michael@0 | 99 | return (T*) this->readFlattenable(T::GetFlattenableType()); |
michael@0 | 100 | } |
michael@0 | 101 | SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilter>(); } |
michael@0 | 102 | SkDrawLooper* readDrawLooper() { return this->readFlattenable<SkDrawLooper>(); } |
michael@0 | 103 | SkImageFilter* readImageFilter() { return this->readFlattenable<SkImageFilter>(); } |
michael@0 | 104 | SkMaskFilter* readMaskFilter() { return this->readFlattenable<SkMaskFilter>(); } |
michael@0 | 105 | SkPathEffect* readPathEffect() { return this->readFlattenable<SkPathEffect>(); } |
michael@0 | 106 | SkPixelRef* readPixelRef() { return this->readFlattenable<SkPixelRef>(); } |
michael@0 | 107 | SkRasterizer* readRasterizer() { return this->readFlattenable<SkRasterizer>(); } |
michael@0 | 108 | SkShader* readShader() { return this->readFlattenable<SkShader>(); } |
michael@0 | 109 | SkUnitMapper* readUnitMapper() { return this->readFlattenable<SkUnitMapper>(); } |
michael@0 | 110 | SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>(); } |
michael@0 | 111 | |
michael@0 | 112 | |
michael@0 | 113 | // binary data and arrays |
michael@0 | 114 | virtual bool readByteArray(void* value, size_t size); |
michael@0 | 115 | virtual bool readColorArray(SkColor* colors, size_t size); |
michael@0 | 116 | virtual bool readIntArray(int32_t* values, size_t size); |
michael@0 | 117 | virtual bool readPointArray(SkPoint* points, size_t size); |
michael@0 | 118 | virtual bool readScalarArray(SkScalar* values, size_t size); |
michael@0 | 119 | |
michael@0 | 120 | SkData* readByteArrayAsData() { |
michael@0 | 121 | size_t len = this->getArrayCount(); |
michael@0 | 122 | if (!this->validateAvailable(len)) { |
michael@0 | 123 | return SkData::NewEmpty(); |
michael@0 | 124 | } |
michael@0 | 125 | void* buffer = sk_malloc_throw(len); |
michael@0 | 126 | this->readByteArray(buffer, len); |
michael@0 | 127 | return SkData::NewFromMalloc(buffer, len); |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | // helpers to get info about arrays and binary data |
michael@0 | 131 | virtual uint32_t getArrayCount(); |
michael@0 | 132 | |
michael@0 | 133 | virtual void readBitmap(SkBitmap* bitmap); |
michael@0 | 134 | virtual SkTypeface* readTypeface(); |
michael@0 | 135 | |
michael@0 | 136 | void setBitmapStorage(SkBitmapHeapReader* bitmapStorage) { |
michael@0 | 137 | SkRefCnt_SafeAssign(fBitmapStorage, bitmapStorage); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | void setTypefaceArray(SkTypeface* array[], int count) { |
michael@0 | 141 | fTFArray = array; |
michael@0 | 142 | fTFCount = count; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | /** |
michael@0 | 146 | * Call this with a pre-loaded array of Factories, in the same order as |
michael@0 | 147 | * were created/written by the writer. SkPicture uses this. |
michael@0 | 148 | */ |
michael@0 | 149 | void setFactoryPlayback(SkFlattenable::Factory array[], int count) { |
michael@0 | 150 | fFactoryTDArray = NULL; |
michael@0 | 151 | fFactoryArray = array; |
michael@0 | 152 | fFactoryCount = count; |
michael@0 | 153 | } |
michael@0 | 154 | |
michael@0 | 155 | /** |
michael@0 | 156 | * Call this with an initially empty array, so the reader can cache each |
michael@0 | 157 | * factory it sees by name. Used by the pipe code in conjunction with |
michael@0 | 158 | * SkWriteBuffer::setNamedFactoryRecorder. |
michael@0 | 159 | */ |
michael@0 | 160 | void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) { |
michael@0 | 161 | fFactoryTDArray = array; |
michael@0 | 162 | fFactoryArray = NULL; |
michael@0 | 163 | fFactoryCount = 0; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Provide a function to decode an SkBitmap from encoded data. Only used if the writer |
michael@0 | 168 | * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the |
michael@0 | 169 | * appropriate size will be used. |
michael@0 | 170 | */ |
michael@0 | 171 | void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { |
michael@0 | 172 | fBitmapDecoder = bitmapDecoder; |
michael@0 | 173 | } |
michael@0 | 174 | |
michael@0 | 175 | // Default impelementations don't check anything. |
michael@0 | 176 | virtual bool validate(bool isValid) { return true; } |
michael@0 | 177 | virtual bool isValid() const { return true; } |
michael@0 | 178 | virtual bool validateAvailable(size_t size) { return true; } |
michael@0 | 179 | |
michael@0 | 180 | protected: |
michael@0 | 181 | SkReader32 fReader; |
michael@0 | 182 | |
michael@0 | 183 | private: |
michael@0 | 184 | bool readArray(void* value, size_t size, size_t elementSize); |
michael@0 | 185 | |
michael@0 | 186 | uint32_t fFlags; |
michael@0 | 187 | |
michael@0 | 188 | void* fMemoryPtr; |
michael@0 | 189 | |
michael@0 | 190 | SkBitmapHeapReader* fBitmapStorage; |
michael@0 | 191 | SkTypeface** fTFArray; |
michael@0 | 192 | int fTFCount; |
michael@0 | 193 | |
michael@0 | 194 | SkTDArray<SkFlattenable::Factory>* fFactoryTDArray; |
michael@0 | 195 | SkFlattenable::Factory* fFactoryArray; |
michael@0 | 196 | int fFactoryCount; |
michael@0 | 197 | |
michael@0 | 198 | SkPicture::InstallPixelRefProc fBitmapDecoder; |
michael@0 | 199 | |
michael@0 | 200 | #ifdef DEBUG_NON_DETERMINISTIC_ASSERT |
michael@0 | 201 | // Debugging counter to keep track of how many bitmaps we |
michael@0 | 202 | // have decoded. |
michael@0 | 203 | int fDecodedBitmapIndex; |
michael@0 | 204 | #endif // DEBUG_NON_DETERMINISTIC_ASSERT |
michael@0 | 205 | }; |
michael@0 | 206 | |
michael@0 | 207 | #endif // SkReadBuffer_DEFINED |