Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "mozilla/Attributes.h" |
michael@0 | 6 | #include "mozilla/ReentrantMonitor.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "imgIEncoder.h" |
michael@0 | 9 | #include "BMPFileHeaders.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "nsCOMPtr.h" |
michael@0 | 12 | |
michael@0 | 13 | #define NS_BMPENCODER_CID \ |
michael@0 | 14 | { /* 13a5320c-4c91-4FA4-bd16-b081a3ba8c0b */ \ |
michael@0 | 15 | 0x13a5320c, \ |
michael@0 | 16 | 0x4c91, \ |
michael@0 | 17 | 0x4fa4, \ |
michael@0 | 18 | {0xbd, 0x16, 0xb0, 0x81, 0xa3, 0Xba, 0x8c, 0x0b} \ |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | // Provides BMP encoding functionality. Use InitFromData() to do the |
michael@0 | 22 | // encoding. See that function definition for encoding options. |
michael@0 | 23 | |
michael@0 | 24 | class nsBMPEncoder MOZ_FINAL : public imgIEncoder |
michael@0 | 25 | { |
michael@0 | 26 | typedef mozilla::ReentrantMonitor ReentrantMonitor; |
michael@0 | 27 | public: |
michael@0 | 28 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 29 | NS_DECL_IMGIENCODER |
michael@0 | 30 | NS_DECL_NSIINPUTSTREAM |
michael@0 | 31 | NS_DECL_NSIASYNCINPUTSTREAM |
michael@0 | 32 | |
michael@0 | 33 | nsBMPEncoder(); |
michael@0 | 34 | ~nsBMPEncoder(); |
michael@0 | 35 | |
michael@0 | 36 | protected: |
michael@0 | 37 | enum Version { |
michael@0 | 38 | VERSION_3 = 3, |
michael@0 | 39 | VERSION_5 = 5 |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | // See InitData in the cpp for valid parse options |
michael@0 | 43 | nsresult ParseOptions(const nsAString& aOptions, Version* version, |
michael@0 | 44 | uint32_t* bpp); |
michael@0 | 45 | // Obtains data with no alpha in machine-independent byte order |
michael@0 | 46 | void ConvertHostARGBRow(const uint8_t* aSrc, uint8_t* aDest, |
michael@0 | 47 | uint32_t aPixelWidth); |
michael@0 | 48 | // Thread safe notify listener |
michael@0 | 49 | void NotifyListener(); |
michael@0 | 50 | |
michael@0 | 51 | // Initializes the bitmap file header member mBMPFileHeader |
michael@0 | 52 | void InitFileHeader(Version aVersion, uint32_t aBPP, uint32_t aWidth, |
michael@0 | 53 | uint32_t aHeight); |
michael@0 | 54 | // Initializes the bitmap info header member mBMPInfoHeader |
michael@0 | 55 | void InitInfoHeader(Version aVersion, uint32_t aBPP, uint32_t aWidth, |
michael@0 | 56 | uint32_t aHeight); |
michael@0 | 57 | |
michael@0 | 58 | // Encodes the bitmap file header member mBMPFileHeader |
michael@0 | 59 | void EncodeFileHeader(); |
michael@0 | 60 | // Encodes the bitmap info header member mBMPInfoHeader |
michael@0 | 61 | void EncodeInfoHeader(); |
michael@0 | 62 | // Encodes a row of image data which does not have alpha data |
michael@0 | 63 | void EncodeImageDataRow24(const uint8_t* aData); |
michael@0 | 64 | // Encodes a row of image data which does have alpha data |
michael@0 | 65 | void EncodeImageDataRow32(const uint8_t* aData); |
michael@0 | 66 | // Obtains the current offset filled up to for the image buffer |
michael@0 | 67 | inline int32_t GetCurrentImageBufferOffset() |
michael@0 | 68 | { |
michael@0 | 69 | return static_cast<int32_t>(mImageBufferCurr - mImageBufferStart); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | // These headers will always contain endian independent stuff |
michael@0 | 73 | // They store the BMP headers which will be encoded |
michael@0 | 74 | mozilla::image::BMPFILEHEADER mBMPFileHeader; |
michael@0 | 75 | mozilla::image::BITMAPV5HEADER mBMPInfoHeader; |
michael@0 | 76 | |
michael@0 | 77 | // Keeps track of the start of the image buffer |
michael@0 | 78 | uint8_t* mImageBufferStart; |
michael@0 | 79 | // Keeps track of the current position in the image buffer |
michael@0 | 80 | uint8_t* mImageBufferCurr; |
michael@0 | 81 | // Keeps track of the image buffer size |
michael@0 | 82 | uint32_t mImageBufferSize; |
michael@0 | 83 | // Keeps track of the number of bytes in the image buffer which are read |
michael@0 | 84 | uint32_t mImageBufferReadPoint; |
michael@0 | 85 | // Stores true if the image is done being encoded |
michael@0 | 86 | bool mFinished; |
michael@0 | 87 | |
michael@0 | 88 | nsCOMPtr<nsIInputStreamCallback> mCallback; |
michael@0 | 89 | nsCOMPtr<nsIEventTarget> mCallbackTarget; |
michael@0 | 90 | uint32_t mNotifyThreshold; |
michael@0 | 91 | }; |