gfx/skia/trunk/include/core/SkMetaData.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 SkMetaData_DEFINED
michael@0 11 #define SkMetaData_DEFINED
michael@0 12
michael@0 13 #include "SkScalar.h"
michael@0 14
michael@0 15 class SkRefCnt;
michael@0 16
michael@0 17 class SK_API SkMetaData {
michael@0 18 public:
michael@0 19 /**
michael@0 20 * Used to manage the life-cycle of a ptr in the metadata. This is option
michael@0 21 * in setPtr, and is only invoked when either copying one metadata to
michael@0 22 * another, or when the metadata is destroyed.
michael@0 23 *
michael@0 24 * setPtr(name, ptr, proc) {
michael@0 25 * fPtr = proc(ptr, true);
michael@0 26 * }
michael@0 27 *
michael@0 28 * copy: A = B {
michael@0 29 * A.fPtr = B.fProc(B.fPtr, true);
michael@0 30 * }
michael@0 31 *
michael@0 32 * ~SkMetaData {
michael@0 33 * fProc(fPtr, false);
michael@0 34 * }
michael@0 35 */
michael@0 36 typedef void* (*PtrProc)(void* ptr, bool doRef);
michael@0 37
michael@0 38 /**
michael@0 39 * Implements PtrProc for SkRefCnt pointers
michael@0 40 */
michael@0 41 static void* RefCntProc(void* ptr, bool doRef);
michael@0 42
michael@0 43 SkMetaData();
michael@0 44 SkMetaData(const SkMetaData& src);
michael@0 45 ~SkMetaData();
michael@0 46
michael@0 47 SkMetaData& operator=(const SkMetaData& src);
michael@0 48
michael@0 49 void reset();
michael@0 50
michael@0 51 bool findS32(const char name[], int32_t* value = NULL) const;
michael@0 52 bool findScalar(const char name[], SkScalar* value = NULL) const;
michael@0 53 const SkScalar* findScalars(const char name[], int* count,
michael@0 54 SkScalar values[] = NULL) const;
michael@0 55 const char* findString(const char name[]) const;
michael@0 56 bool findPtr(const char name[], void** value = NULL, PtrProc* = NULL) const;
michael@0 57 bool findBool(const char name[], bool* value = NULL) const;
michael@0 58 const void* findData(const char name[], size_t* byteCount = NULL) const;
michael@0 59
michael@0 60 bool hasS32(const char name[], int32_t value) const {
michael@0 61 int32_t v;
michael@0 62 return this->findS32(name, &v) && v == value;
michael@0 63 }
michael@0 64 bool hasScalar(const char name[], SkScalar value) const {
michael@0 65 SkScalar v;
michael@0 66 return this->findScalar(name, &v) && v == value;
michael@0 67 }
michael@0 68 bool hasString(const char name[], const char value[]) const {
michael@0 69 const char* v = this->findString(name);
michael@0 70 return (v == NULL && value == NULL) ||
michael@0 71 (v != NULL && value != NULL && !strcmp(v, value));
michael@0 72 }
michael@0 73 bool hasPtr(const char name[], void* value) const {
michael@0 74 void* v;
michael@0 75 return this->findPtr(name, &v) && v == value;
michael@0 76 }
michael@0 77 bool hasBool(const char name[], bool value) const {
michael@0 78 bool v;
michael@0 79 return this->findBool(name, &v) && v == value;
michael@0 80 }
michael@0 81 bool hasData(const char name[], const void* data, size_t byteCount) const {
michael@0 82 size_t len;
michael@0 83 const void* ptr = this->findData(name, &len);
michael@0 84 return NULL != ptr && len == byteCount && !memcmp(ptr, data, len);
michael@0 85 }
michael@0 86
michael@0 87 void setS32(const char name[], int32_t value);
michael@0 88 void setScalar(const char name[], SkScalar value);
michael@0 89 SkScalar* setScalars(const char name[], int count, const SkScalar values[] = NULL);
michael@0 90 void setString(const char name[], const char value[]);
michael@0 91 void setPtr(const char name[], void* value, PtrProc proc = NULL);
michael@0 92 void setBool(const char name[], bool value);
michael@0 93 // the data is copied from the input pointer.
michael@0 94 void setData(const char name[], const void* data, size_t byteCount);
michael@0 95
michael@0 96 bool removeS32(const char name[]);
michael@0 97 bool removeScalar(const char name[]);
michael@0 98 bool removeString(const char name[]);
michael@0 99 bool removePtr(const char name[]);
michael@0 100 bool removeBool(const char name[]);
michael@0 101 bool removeData(const char name[]);
michael@0 102
michael@0 103 // helpers for SkRefCnt
michael@0 104 bool findRefCnt(const char name[], SkRefCnt** ptr = NULL) {
michael@0 105 return this->findPtr(name, reinterpret_cast<void**>(ptr));
michael@0 106 }
michael@0 107 bool hasRefCnt(const char name[], SkRefCnt* ptr) {
michael@0 108 return this->hasPtr(name, ptr);
michael@0 109 }
michael@0 110 void setRefCnt(const char name[], SkRefCnt* ptr) {
michael@0 111 this->setPtr(name, ptr, RefCntProc);
michael@0 112 }
michael@0 113 bool removeRefCnt(const char name[]) {
michael@0 114 return this->removePtr(name);
michael@0 115 }
michael@0 116
michael@0 117 enum Type {
michael@0 118 kS32_Type,
michael@0 119 kScalar_Type,
michael@0 120 kString_Type,
michael@0 121 kPtr_Type,
michael@0 122 kBool_Type,
michael@0 123 kData_Type,
michael@0 124
michael@0 125 kTypeCount
michael@0 126 };
michael@0 127
michael@0 128 struct Rec;
michael@0 129 class Iter;
michael@0 130 friend class Iter;
michael@0 131
michael@0 132 class Iter {
michael@0 133 public:
michael@0 134 Iter() : fRec(NULL) {}
michael@0 135 Iter(const SkMetaData&);
michael@0 136
michael@0 137 /** Reset the iterator, so that calling next() will return the first
michael@0 138 data element. This is done implicitly in the constructor.
michael@0 139 */
michael@0 140 void reset(const SkMetaData&);
michael@0 141
michael@0 142 /** Each time next is called, it returns the name of the next data element,
michael@0 143 or null when there are no more elements. If non-null is returned, then the
michael@0 144 element's type is returned (if not null), and the number of data values
michael@0 145 is returned in count (if not null).
michael@0 146 */
michael@0 147 const char* next(Type*, int* count);
michael@0 148
michael@0 149 private:
michael@0 150 Rec* fRec;
michael@0 151 };
michael@0 152
michael@0 153 public:
michael@0 154 struct Rec {
michael@0 155 Rec* fNext;
michael@0 156 uint16_t fDataCount; // number of elements
michael@0 157 uint8_t fDataLen; // sizeof a single element
michael@0 158 uint8_t fType;
michael@0 159
michael@0 160 const void* data() const { return (this + 1); }
michael@0 161 void* data() { return (this + 1); }
michael@0 162 const char* name() const { return (const char*)this->data() + fDataLen * fDataCount; }
michael@0 163 char* name() { return (char*)this->data() + fDataLen * fDataCount; }
michael@0 164
michael@0 165 static Rec* Alloc(size_t);
michael@0 166 static void Free(Rec*);
michael@0 167 };
michael@0 168 Rec* fRec;
michael@0 169
michael@0 170 const Rec* find(const char name[], Type) const;
michael@0 171 void* set(const char name[], const void* data, size_t len, Type, int count);
michael@0 172 bool remove(const char name[], Type);
michael@0 173 };
michael@0 174
michael@0 175 #endif

mercurial