Chromium Code Reviews| Index: include/core/SkFlattenableBuffers.h |
| diff --git a/include/core/SkFlattenableBuffers.h b/include/core/SkFlattenableBuffers.h |
| index 03c03f3877e6f8e3f508d29e371d5c7ebd91624e..f4b64cdffa2b44c3ad66b59bd5f4314369d1cede 100644 |
| --- a/include/core/SkFlattenableBuffers.h |
| +++ b/include/core/SkFlattenableBuffers.h |
| @@ -41,14 +41,20 @@ public: |
| kCrossProcess_Flag = 1 << 0, |
| kScalarIsFloat_Flag = 1 << 1, |
| kPtrIs64Bit_Flag = 1 << 2, |
| + /** The kValidation_Flag is used to force stream validations (by making |
| + * sure that no operation reads past the end of the stream, for example) |
| + * and error handling if any reading operation yields an invalid value. |
| + */ |
| + kValidation_Flag = 1 << 3, |
| }; |
| void setFlags(uint32_t flags) { fFlags = flags; } |
| uint32_t getFlags() const { return fFlags; } |
| - bool isCrossProcess() const { return SkToBool(fFlags & kCrossProcess_Flag); } |
| + bool isCrossProcess() const { return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); } |
| bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); } |
| bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); } |
| + bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); } |
| // primitives |
| virtual bool readBool() = 0; |
| @@ -64,7 +70,16 @@ public: |
| virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encoding) = 0; |
| // common data structures |
| - virtual SkFlattenable* readFlattenable() = 0; |
| + virtual SkFlattenable* readFlattenable( |
| + /** |
| + @param type This parameter is only used when using SkValidatingReadBuffer. It will verify |
| + that the object about to be deserialized is of the given type or early return |
| + NULL otherwise. The type provided here is either the same type or the type of |
| + one of the base classes of the object to deserialize. This can effectively be |
| + bypassed by providing the type SkFlattenable::kSkFlattenable_Type here, since |
| + SkFlattenable is a base class to all other classes that can be deserialized. |
| + */ |
| + SkFlattenable::Type type = SkFlattenable::kSkFlattenable_Type) = 0; |
| virtual void readPoint(SkPoint* point) = 0; |
| virtual void readMatrix(SkMatrix* matrix) = 0; |
| virtual void readIRect(SkIRect* rect) = 0; |
| @@ -99,9 +114,16 @@ public: |
| } |
| template <typename T> T* readFlattenableT() { |
| - return static_cast<T*>(this->readFlattenable()); |
| + return static_cast<T*>(this->readFlattenable(T::GetType())); |
| } |
| + void validate(bool isValid) { |
| + fError |= !isValid; |
|
Stephen White
2013/10/02 17:41:43
Nit: bitwise operator on a bool; I prefer the logi
sugoi1
2013/10/02 19:59:32
Done.
|
| + } |
| + |
| +protected: |
| + bool fError; |
| + |
| private: |
| uint32_t fFlags; |
| }; |
| @@ -154,13 +176,22 @@ public: |
| enum Flags { |
| kCrossProcess_Flag = 0x01, |
| + /** The kValidation_Flag is used here to make sure the write operation |
| + * is symmetric with the read operation using the equivalent flag |
| + * SkFlattenableReadBuffer::kValidation_Flag. |
| + */ |
| + kValidation_Flag = 0x02, |
| }; |
| uint32_t getFlags() const { return fFlags; } |
| void setFlags(uint32_t flags) { fFlags = flags; } |
| bool isCrossProcess() const { |
| - return SkToBool(fFlags & kCrossProcess_Flag); |
| + return SkToBool(fFlags & (kCrossProcess_Flag | kValidation_Flag)); |
| + } |
| + |
| + bool isValidating() const { |
| + return SkToBool(fFlags & kValidation_Flag); |
| } |
| bool persistTypeface() const { return (fFlags & kCrossProcess_Flag) != 0; } |