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 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include <algorithm> // min & max |
michael@0 | 7 | #include <cstdlib> |
michael@0 | 8 | #include <stdint.h> |
michael@0 | 9 | #include <stdio.h> |
michael@0 | 10 | #include <stdlib.h> |
michael@0 | 11 | #include <string.h> |
michael@0 | 12 | |
michael@0 | 13 | void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight, |
michael@0 | 14 | int aByteStride, int aXBoundary, int aYBoundary) |
michael@0 | 15 | { |
michael@0 | 16 | if (aXBoundary != 0) { |
michael@0 | 17 | uint8_t* line = new uint8_t[aByteWidth]; |
michael@0 | 18 | uint32_t smallStart = 0; |
michael@0 | 19 | uint32_t smallLen = aXBoundary; |
michael@0 | 20 | uint32_t smallDest = aByteWidth - aXBoundary; |
michael@0 | 21 | uint32_t largeStart = aXBoundary; |
michael@0 | 22 | uint32_t largeLen = aByteWidth - aXBoundary; |
michael@0 | 23 | uint32_t largeDest = 0; |
michael@0 | 24 | if (aXBoundary > aByteWidth / 2) { |
michael@0 | 25 | smallStart = aXBoundary; |
michael@0 | 26 | smallLen = aByteWidth - aXBoundary; |
michael@0 | 27 | smallDest = 0; |
michael@0 | 28 | largeStart = 0; |
michael@0 | 29 | largeLen = aXBoundary; |
michael@0 | 30 | largeDest = smallLen; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | for (int y = 0; y < aHeight; y++) { |
michael@0 | 34 | int yOffset = y * aByteStride; |
michael@0 | 35 | memcpy(line, &aBuffer[yOffset + smallStart], smallLen); |
michael@0 | 36 | memmove(&aBuffer[yOffset + largeDest], &aBuffer[yOffset + largeStart], largeLen); |
michael@0 | 37 | memcpy(&aBuffer[yOffset + smallDest], line, smallLen); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | delete[] line; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | if (aYBoundary != 0) { |
michael@0 | 44 | uint32_t smallestHeight = std::min(aHeight - aYBoundary, aYBoundary); |
michael@0 | 45 | uint32_t largestHeight = std::max(aHeight - aYBoundary, aYBoundary); |
michael@0 | 46 | uint32_t smallOffset = 0; |
michael@0 | 47 | uint32_t largeOffset = aYBoundary * aByteStride; |
michael@0 | 48 | uint32_t largeDestOffset = 0; |
michael@0 | 49 | uint32_t smallDestOffset = largestHeight * aByteStride; |
michael@0 | 50 | if (aYBoundary > aHeight / 2) { |
michael@0 | 51 | smallOffset = aYBoundary * aByteStride; |
michael@0 | 52 | largeOffset = 0; |
michael@0 | 53 | largeDestOffset = smallestHeight * aByteStride; |
michael@0 | 54 | smallDestOffset = 0; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | uint8_t* smallestSide = new uint8_t[aByteStride * smallestHeight]; |
michael@0 | 58 | memcpy(smallestSide, &aBuffer[smallOffset], aByteStride * smallestHeight); |
michael@0 | 59 | memmove(&aBuffer[largeDestOffset], &aBuffer[largeOffset], aByteStride * largestHeight); |
michael@0 | 60 | memcpy(&aBuffer[smallDestOffset], smallestSide, aByteStride * smallestHeight); |
michael@0 | 61 | delete[] smallestSide; |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 |