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 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 | #include "SkImageDecoder.h" |
michael@0 | 11 | #include "SkColor.h" |
michael@0 | 12 | #include "SkColorPriv.h" |
michael@0 | 13 | #include "SkMath.h" |
michael@0 | 14 | #include "SkStream.h" |
michael@0 | 15 | #include "SkTemplates.h" |
michael@0 | 16 | #include "SkUtils.h" |
michael@0 | 17 | |
michael@0 | 18 | class SkWBMPImageDecoder : public SkImageDecoder { |
michael@0 | 19 | public: |
michael@0 | 20 | virtual Format getFormat() const SK_OVERRIDE { |
michael@0 | 21 | return kWBMP_Format; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | protected: |
michael@0 | 25 | virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode) SK_OVERRIDE; |
michael@0 | 26 | |
michael@0 | 27 | private: |
michael@0 | 28 | typedef SkImageDecoder INHERITED; |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | static bool read_byte(SkStream* stream, uint8_t* data) |
michael@0 | 32 | { |
michael@0 | 33 | return stream->read(data, 1) == 1; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | static bool read_mbf(SkStream* stream, int* value) |
michael@0 | 37 | { |
michael@0 | 38 | int n = 0; |
michael@0 | 39 | uint8_t data; |
michael@0 | 40 | do { |
michael@0 | 41 | if (!read_byte(stream, &data)) { |
michael@0 | 42 | return false; |
michael@0 | 43 | } |
michael@0 | 44 | n = (n << 7) | (data & 0x7F); |
michael@0 | 45 | } while (data & 0x80); |
michael@0 | 46 | |
michael@0 | 47 | *value = n; |
michael@0 | 48 | return true; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | struct wbmp_head { |
michael@0 | 52 | int fWidth; |
michael@0 | 53 | int fHeight; |
michael@0 | 54 | |
michael@0 | 55 | bool init(SkStream* stream) |
michael@0 | 56 | { |
michael@0 | 57 | uint8_t data; |
michael@0 | 58 | |
michael@0 | 59 | if (!read_byte(stream, &data) || data != 0) { // unknown type |
michael@0 | 60 | return false; |
michael@0 | 61 | } |
michael@0 | 62 | if (!read_byte(stream, &data) || (data & 0x9F)) { // skip fixed header |
michael@0 | 63 | return false; |
michael@0 | 64 | } |
michael@0 | 65 | if (!read_mbf(stream, &fWidth) || (unsigned)fWidth > 0xFFFF) { |
michael@0 | 66 | return false; |
michael@0 | 67 | } |
michael@0 | 68 | if (!read_mbf(stream, &fHeight) || (unsigned)fHeight > 0xFFFF) { |
michael@0 | 69 | return false; |
michael@0 | 70 | } |
michael@0 | 71 | return fWidth != 0 && fHeight != 0; |
michael@0 | 72 | } |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | static void expand_bits_to_bytes(uint8_t dst[], const uint8_t src[], int bits) |
michael@0 | 76 | { |
michael@0 | 77 | int bytes = bits >> 3; |
michael@0 | 78 | |
michael@0 | 79 | for (int i = 0; i < bytes; i++) { |
michael@0 | 80 | unsigned mask = *src++; |
michael@0 | 81 | dst[0] = (mask >> 7) & 1; |
michael@0 | 82 | dst[1] = (mask >> 6) & 1; |
michael@0 | 83 | dst[2] = (mask >> 5) & 1; |
michael@0 | 84 | dst[3] = (mask >> 4) & 1; |
michael@0 | 85 | dst[4] = (mask >> 3) & 1; |
michael@0 | 86 | dst[5] = (mask >> 2) & 1; |
michael@0 | 87 | dst[6] = (mask >> 1) & 1; |
michael@0 | 88 | dst[7] = (mask >> 0) & 1; |
michael@0 | 89 | dst += 8; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | bits &= 7; |
michael@0 | 93 | if (bits > 0) { |
michael@0 | 94 | unsigned mask = *src; |
michael@0 | 95 | do { |
michael@0 | 96 | *dst++ = (mask >> 7) & 1;; |
michael@0 | 97 | mask <<= 1; |
michael@0 | 98 | } while (--bits != 0); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | bool SkWBMPImageDecoder::onDecode(SkStream* stream, SkBitmap* decodedBitmap, |
michael@0 | 103 | Mode mode) |
michael@0 | 104 | { |
michael@0 | 105 | wbmp_head head; |
michael@0 | 106 | |
michael@0 | 107 | if (!head.init(stream)) { |
michael@0 | 108 | return false; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | int width = head.fWidth; |
michael@0 | 112 | int height = head.fHeight; |
michael@0 | 113 | |
michael@0 | 114 | decodedBitmap->setConfig(SkBitmap::kIndex8_Config, width, height, 0, |
michael@0 | 115 | kOpaque_SkAlphaType); |
michael@0 | 116 | |
michael@0 | 117 | if (SkImageDecoder::kDecodeBounds_Mode == mode) { |
michael@0 | 118 | return true; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | const SkPMColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; |
michael@0 | 122 | SkColorTable* ct = SkNEW_ARGS(SkColorTable, (colors, 2)); |
michael@0 | 123 | SkAutoUnref aur(ct); |
michael@0 | 124 | |
michael@0 | 125 | if (!this->allocPixelRef(decodedBitmap, ct)) { |
michael@0 | 126 | return false; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | SkAutoLockPixels alp(*decodedBitmap); |
michael@0 | 130 | |
michael@0 | 131 | uint8_t* dst = decodedBitmap->getAddr8(0, 0); |
michael@0 | 132 | // store the 1-bit valuess at the end of our pixels, so we won't stomp |
michael@0 | 133 | // on them before we're read them. Just trying to avoid a temp allocation |
michael@0 | 134 | size_t srcRB = SkAlign8(width) >> 3; |
michael@0 | 135 | size_t srcSize = height * srcRB; |
michael@0 | 136 | uint8_t* src = dst + decodedBitmap->getSize() - srcSize; |
michael@0 | 137 | if (stream->read(src, srcSize) != srcSize) { |
michael@0 | 138 | return false; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | for (int y = 0; y < height; y++) |
michael@0 | 142 | { |
michael@0 | 143 | expand_bits_to_bytes(dst, src, width); |
michael@0 | 144 | dst += decodedBitmap->rowBytes(); |
michael@0 | 145 | src += srcRB; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | return true; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 152 | DEFINE_DECODER_CREATOR(WBMPImageDecoder); |
michael@0 | 153 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 154 | |
michael@0 | 155 | static SkImageDecoder* sk_wbmp_dfactory(SkStreamRewindable* stream) { |
michael@0 | 156 | wbmp_head head; |
michael@0 | 157 | |
michael@0 | 158 | if (head.init(stream)) { |
michael@0 | 159 | return SkNEW(SkWBMPImageDecoder); |
michael@0 | 160 | } |
michael@0 | 161 | return NULL; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | static SkImageDecoder::Format get_format_wbmp(SkStreamRewindable* stream) { |
michael@0 | 165 | wbmp_head head; |
michael@0 | 166 | if (head.init(stream)) { |
michael@0 | 167 | return SkImageDecoder::kWBMP_Format; |
michael@0 | 168 | } |
michael@0 | 169 | return SkImageDecoder::kUnknown_Format; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | static SkImageDecoder_DecodeReg gDReg(sk_wbmp_dfactory); |
michael@0 | 173 | static SkImageDecoder_FormatReg gFormatReg(get_format_wbmp); |