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 | // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. |
michael@0 | 3 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | // found in the LICENSE file. |
michael@0 | 5 | // |
michael@0 | 6 | |
michael@0 | 7 | // BinaryStream.h: Provides binary serialization of simple types. |
michael@0 | 8 | |
michael@0 | 9 | #ifndef LIBGLESV2_BINARYSTREAM_H_ |
michael@0 | 10 | #define LIBGLESV2_BINARYSTREAM_H_ |
michael@0 | 11 | |
michael@0 | 12 | #include "common/angleutils.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace gl |
michael@0 | 15 | { |
michael@0 | 16 | |
michael@0 | 17 | class BinaryInputStream |
michael@0 | 18 | { |
michael@0 | 19 | public: |
michael@0 | 20 | BinaryInputStream(const void *data, size_t length) |
michael@0 | 21 | { |
michael@0 | 22 | mError = false; |
michael@0 | 23 | mOffset = 0; |
michael@0 | 24 | mData = static_cast<const char*>(data); |
michael@0 | 25 | mLength = length; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | template <typename T> |
michael@0 | 29 | void read(T *v, size_t num) |
michael@0 | 30 | { |
michael@0 | 31 | union |
michael@0 | 32 | { |
michael@0 | 33 | T dummy; // Compilation error for non-trivial types |
michael@0 | 34 | } dummy; |
michael@0 | 35 | (void) dummy; |
michael@0 | 36 | |
michael@0 | 37 | if (mError) |
michael@0 | 38 | { |
michael@0 | 39 | return; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | size_t length = num * sizeof(T); |
michael@0 | 43 | |
michael@0 | 44 | if (mOffset + length > mLength) |
michael@0 | 45 | { |
michael@0 | 46 | mError = true; |
michael@0 | 47 | return; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | memcpy(v, mData + mOffset, length); |
michael@0 | 51 | mOffset += length; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | template <typename T> |
michael@0 | 55 | void read(T * v) |
michael@0 | 56 | { |
michael@0 | 57 | read(v, 1); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | void read(std::string *v) |
michael@0 | 61 | { |
michael@0 | 62 | size_t length; |
michael@0 | 63 | read(&length); |
michael@0 | 64 | |
michael@0 | 65 | if (mError) |
michael@0 | 66 | { |
michael@0 | 67 | return; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | if (mOffset + length > mLength) |
michael@0 | 71 | { |
michael@0 | 72 | mError = true; |
michael@0 | 73 | return; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | v->assign(mData + mOffset, length); |
michael@0 | 77 | mOffset += length; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | void skip(size_t length) |
michael@0 | 81 | { |
michael@0 | 82 | if (mOffset + length > mLength) |
michael@0 | 83 | { |
michael@0 | 84 | mError = true; |
michael@0 | 85 | return; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | mOffset += length; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | size_t offset() const |
michael@0 | 92 | { |
michael@0 | 93 | return mOffset; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | bool error() const |
michael@0 | 97 | { |
michael@0 | 98 | return mError; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | bool endOfStream() const |
michael@0 | 102 | { |
michael@0 | 103 | return mOffset == mLength; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | private: |
michael@0 | 107 | DISALLOW_COPY_AND_ASSIGN(BinaryInputStream); |
michael@0 | 108 | bool mError; |
michael@0 | 109 | size_t mOffset; |
michael@0 | 110 | const char *mData; |
michael@0 | 111 | size_t mLength; |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | class BinaryOutputStream |
michael@0 | 115 | { |
michael@0 | 116 | public: |
michael@0 | 117 | BinaryOutputStream() |
michael@0 | 118 | { |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | template <typename T> |
michael@0 | 122 | void write(const T *v, size_t num) |
michael@0 | 123 | { |
michael@0 | 124 | union |
michael@0 | 125 | { |
michael@0 | 126 | T dummy; // Compilation error for non-trivial types |
michael@0 | 127 | } dummy; |
michael@0 | 128 | (void) dummy; |
michael@0 | 129 | |
michael@0 | 130 | const char *asBytes = reinterpret_cast<const char*>(v); |
michael@0 | 131 | mData.insert(mData.end(), asBytes, asBytes + num * sizeof(T)); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | template <typename T> |
michael@0 | 135 | void write(const T &v) |
michael@0 | 136 | { |
michael@0 | 137 | write(&v, 1); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | void write(const std::string &v) |
michael@0 | 141 | { |
michael@0 | 142 | size_t length = v.length(); |
michael@0 | 143 | write(length); |
michael@0 | 144 | |
michael@0 | 145 | write(v.c_str(), length); |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | size_t length() const |
michael@0 | 149 | { |
michael@0 | 150 | return mData.size(); |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | const void* data() const |
michael@0 | 154 | { |
michael@0 | 155 | return mData.size() ? &mData[0] : NULL; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | private: |
michael@0 | 159 | DISALLOW_COPY_AND_ASSIGN(BinaryOutputStream); |
michael@0 | 160 | std::vector<char> mData; |
michael@0 | 161 | }; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | #endif // LIBGLESV2_BINARYSTREAM_H_ |