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 | |
michael@0 | 10 | |
michael@0 | 11 | #ifndef SkData_DEFINED |
michael@0 | 12 | #define SkData_DEFINED |
michael@0 | 13 | |
michael@0 | 14 | #include "SkRefCnt.h" |
michael@0 | 15 | |
michael@0 | 16 | struct SkFILE; |
michael@0 | 17 | |
michael@0 | 18 | /** |
michael@0 | 19 | * SkData holds an immutable data buffer. Not only is the data immutable, |
michael@0 | 20 | * but the actual ptr that is returned (by data() or bytes()) is guaranteed |
michael@0 | 21 | * to always be the same for the life of this instance. |
michael@0 | 22 | */ |
michael@0 | 23 | class SK_API SkData : public SkRefCnt { |
michael@0 | 24 | public: |
michael@0 | 25 | SK_DECLARE_INST_COUNT(SkData) |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * Returns the number of bytes stored. |
michael@0 | 29 | */ |
michael@0 | 30 | size_t size() const { return fSize; } |
michael@0 | 31 | |
michael@0 | 32 | bool isEmpty() const { return 0 == fSize; } |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * Returns the ptr to the data. |
michael@0 | 36 | */ |
michael@0 | 37 | const void* data() const { return fPtr; } |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * Like data(), returns a read-only ptr into the data, but in this case |
michael@0 | 41 | * it is cast to uint8_t*, to make it easy to add an offset to it. |
michael@0 | 42 | */ |
michael@0 | 43 | const uint8_t* bytes() const { |
michael@0 | 44 | return reinterpret_cast<const uint8_t*>(fPtr); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | /** |
michael@0 | 48 | * Helper to copy a range of the data into a caller-provided buffer. |
michael@0 | 49 | * Returns the actual number of bytes copied, after clamping offset and |
michael@0 | 50 | * length to the size of the data. If buffer is NULL, it is ignored, and |
michael@0 | 51 | * only the computed number of bytes is returned. |
michael@0 | 52 | */ |
michael@0 | 53 | size_t copyRange(size_t offset, size_t length, void* buffer) const; |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Returns true if these two objects have the same length and contents, |
michael@0 | 57 | * effectively returning 0 == memcmp(...) |
michael@0 | 58 | */ |
michael@0 | 59 | bool equals(const SkData* other) const; |
michael@0 | 60 | |
michael@0 | 61 | /** |
michael@0 | 62 | * Function that, if provided, will be called when the SkData goes out |
michael@0 | 63 | * of scope, allowing for custom allocation/freeing of the data. |
michael@0 | 64 | */ |
michael@0 | 65 | typedef void (*ReleaseProc)(const void* ptr, size_t length, void* context); |
michael@0 | 66 | |
michael@0 | 67 | /** |
michael@0 | 68 | * Create a new dataref by copying the specified data |
michael@0 | 69 | */ |
michael@0 | 70 | static SkData* NewWithCopy(const void* data, size_t length); |
michael@0 | 71 | |
michael@0 | 72 | /** |
michael@0 | 73 | * Create a new dataref by copying the specified c-string |
michael@0 | 74 | * (a null-terminated array of bytes). The returned SkData will have size() |
michael@0 | 75 | * equal to strlen(cstr) + 1. If cstr is NULL, it will be treated the same |
michael@0 | 76 | * as "". |
michael@0 | 77 | */ |
michael@0 | 78 | static SkData* NewWithCString(const char cstr[]); |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * Create a new dataref, taking the data ptr as is, and using the |
michael@0 | 82 | * releaseproc to free it. The proc may be NULL. |
michael@0 | 83 | */ |
michael@0 | 84 | static SkData* NewWithProc(const void* data, size_t length, |
michael@0 | 85 | ReleaseProc proc, void* context); |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Create a new dataref from a pointer allocated by malloc. The Data object |
michael@0 | 89 | * takes ownership of that allocation, and will handling calling sk_free. |
michael@0 | 90 | */ |
michael@0 | 91 | static SkData* NewFromMalloc(const void* data, size_t length); |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Create a new dataref the file with the specified path. |
michael@0 | 95 | * If the file cannot be opened, this returns NULL. |
michael@0 | 96 | */ |
michael@0 | 97 | static SkData* NewFromFileName(const char path[]); |
michael@0 | 98 | |
michael@0 | 99 | /** |
michael@0 | 100 | * Create a new dataref from a SkFILE. |
michael@0 | 101 | * This does not take ownership of the SkFILE, nor close it. |
michael@0 | 102 | * The caller is free to close the SkFILE at its convenience. |
michael@0 | 103 | * The SkFILE must be open for reading only. |
michael@0 | 104 | * Returns NULL on failure. |
michael@0 | 105 | */ |
michael@0 | 106 | static SkData* NewFromFILE(SkFILE* f); |
michael@0 | 107 | |
michael@0 | 108 | /** |
michael@0 | 109 | * Create a new dataref from a file descriptor. |
michael@0 | 110 | * This does not take ownership of the file descriptor, nor close it. |
michael@0 | 111 | * The caller is free to close the file descriptor at its convenience. |
michael@0 | 112 | * The file descriptor must be open for reading only. |
michael@0 | 113 | * Returns NULL on failure. |
michael@0 | 114 | */ |
michael@0 | 115 | static SkData* NewFromFD(int fd); |
michael@0 | 116 | |
michael@0 | 117 | /** |
michael@0 | 118 | * Create a new dataref using a subset of the data in the specified |
michael@0 | 119 | * src dataref. |
michael@0 | 120 | */ |
michael@0 | 121 | static SkData* NewSubset(const SkData* src, size_t offset, size_t length); |
michael@0 | 122 | |
michael@0 | 123 | /** |
michael@0 | 124 | * Returns a new empty dataref (or a reference to a shared empty dataref). |
michael@0 | 125 | * New or shared, the caller must see that unref() is eventually called. |
michael@0 | 126 | */ |
michael@0 | 127 | static SkData* NewEmpty(); |
michael@0 | 128 | |
michael@0 | 129 | private: |
michael@0 | 130 | ReleaseProc fReleaseProc; |
michael@0 | 131 | void* fReleaseProcContext; |
michael@0 | 132 | |
michael@0 | 133 | const void* fPtr; |
michael@0 | 134 | size_t fSize; |
michael@0 | 135 | |
michael@0 | 136 | SkData(const void* ptr, size_t size, ReleaseProc, void* context); |
michael@0 | 137 | virtual ~SkData(); |
michael@0 | 138 | |
michael@0 | 139 | // Called the first time someone calls NewEmpty to initialize the singleton. |
michael@0 | 140 | static void NewEmptyImpl(int/*unused*/); |
michael@0 | 141 | |
michael@0 | 142 | typedef SkRefCnt INHERITED; |
michael@0 | 143 | }; |
michael@0 | 144 | |
michael@0 | 145 | /** Typedef of SkAutoTUnref<SkData> for automatically unref-ing a SkData. */ |
michael@0 | 146 | typedef SkAutoTUnref<SkData> SkAutoDataUnref; |
michael@0 | 147 | |
michael@0 | 148 | #endif |