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 2012 Google Inc. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | * found in the LICENSE file. |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "SkBitmap.h" |
michael@0 | 9 | #include "SkBitmapHasher.h" |
michael@0 | 10 | #include "SkEndian.h" |
michael@0 | 11 | #include "SkImageEncoder.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "SkMD5.h" |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * Write an int32 value to a stream in little-endian order. |
michael@0 | 17 | */ |
michael@0 | 18 | static void write_int32_to_buffer(uint32_t val, SkWStream* out) { |
michael@0 | 19 | val = SkEndian_SwapLE32(val); |
michael@0 | 20 | for (size_t byte = 0; byte < 4; ++byte) { |
michael@0 | 21 | out->write8((uint8_t)(val & 0xff)); |
michael@0 | 22 | val = val >> 8; |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * Return the first 8 bytes of a bytearray, encoded as a little-endian uint64. |
michael@0 | 28 | */ |
michael@0 | 29 | static inline uint64_t first_8_bytes_as_uint64(const uint8_t *bytearray) { |
michael@0 | 30 | return SkEndian_SwapLE64(*(reinterpret_cast<const uint64_t *>(bytearray))); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | /*static*/ bool SkBitmapHasher::ComputeDigestInternal(const SkBitmap& bitmap, uint64_t *result) { |
michael@0 | 34 | SkMD5 out; |
michael@0 | 35 | |
michael@0 | 36 | // start with the x/y dimensions |
michael@0 | 37 | write_int32_to_buffer(SkToU32(bitmap.width()), &out); |
michael@0 | 38 | write_int32_to_buffer(SkToU32(bitmap.height()), &out); |
michael@0 | 39 | |
michael@0 | 40 | // add all the pixel data |
michael@0 | 41 | SkAutoTDelete<SkImageEncoder> enc(CreateARGBImageEncoder()); |
michael@0 | 42 | if (!enc->encodeStream(&out, bitmap, SkImageEncoder::kDefaultQuality)) { |
michael@0 | 43 | return false; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | SkMD5::Digest digest; |
michael@0 | 47 | out.finish(digest); |
michael@0 | 48 | *result = first_8_bytes_as_uint64(digest.data); |
michael@0 | 49 | return true; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | /*static*/ bool SkBitmapHasher::ComputeDigest(const SkBitmap& bitmap, uint64_t *result) { |
michael@0 | 53 | if (ComputeDigestInternal(bitmap, result)) { |
michael@0 | 54 | return true; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // Hmm, that didn't work. Maybe if we create a new |
michael@0 | 58 | // kARGB_8888_Config version of the bitmap it will work better? |
michael@0 | 59 | SkBitmap copyBitmap; |
michael@0 | 60 | if (!bitmap.copyTo(©Bitmap, kPMColor_SkColorType)) { |
michael@0 | 61 | return false; |
michael@0 | 62 | } |
michael@0 | 63 | return ComputeDigestInternal(copyBitmap, result); |
michael@0 | 64 | } |