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 | |
michael@0 | 10 | #include "nsAutoPtr.h" |
michael@0 | 11 | #include "nsCOMPtr.h" |
michael@0 | 12 | #include "ICOFileHeaders.h" |
michael@0 | 13 | |
michael@0 | 14 | class nsBMPEncoder; |
michael@0 | 15 | class nsPNGEncoder; |
michael@0 | 16 | |
michael@0 | 17 | #define NS_ICOENCODER_CID \ |
michael@0 | 18 | { /*92AE3AB2-8968-41B1-8709-B6123BCEAF21 */ \ |
michael@0 | 19 | 0x92ae3ab2, \ |
michael@0 | 20 | 0x8968, \ |
michael@0 | 21 | 0x41b1, \ |
michael@0 | 22 | {0x87, 0x09, 0xb6, 0x12, 0x3b, 0Xce, 0xaf, 0x21} \ |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | // Provides ICO encoding functionality. Use InitFromData() to do the |
michael@0 | 26 | // encoding. See that function definition for encoding options. |
michael@0 | 27 | |
michael@0 | 28 | class nsICOEncoder MOZ_FINAL : public imgIEncoder |
michael@0 | 29 | { |
michael@0 | 30 | typedef mozilla::ReentrantMonitor ReentrantMonitor; |
michael@0 | 31 | public: |
michael@0 | 32 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 33 | NS_DECL_IMGIENCODER |
michael@0 | 34 | NS_DECL_NSIINPUTSTREAM |
michael@0 | 35 | NS_DECL_NSIASYNCINPUTSTREAM |
michael@0 | 36 | |
michael@0 | 37 | nsICOEncoder(); |
michael@0 | 38 | ~nsICOEncoder(); |
michael@0 | 39 | |
michael@0 | 40 | // Obtains the width of the icon directory entry |
michael@0 | 41 | uint32_t GetRealWidth() const |
michael@0 | 42 | { |
michael@0 | 43 | return mICODirEntry.mWidth == 0 ? 256 : mICODirEntry.mWidth; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | // Obtains the height of the icon directory entry |
michael@0 | 47 | uint32_t GetRealHeight() const |
michael@0 | 48 | { |
michael@0 | 49 | return mICODirEntry.mHeight == 0 ? 256 : mICODirEntry.mHeight; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | protected: |
michael@0 | 53 | nsresult ParseOptions(const nsAString& aOptions, uint32_t* bpp, |
michael@0 | 54 | bool *usePNG); |
michael@0 | 55 | void NotifyListener(); |
michael@0 | 56 | |
michael@0 | 57 | // Initializes the icon file header mICOFileHeader |
michael@0 | 58 | void InitFileHeader(); |
michael@0 | 59 | // Initializes the icon directory info header mICODirEntry |
michael@0 | 60 | void InitInfoHeader(uint32_t aBPP, uint8_t aWidth, uint8_t aHeight); |
michael@0 | 61 | // Encodes the icon file header mICOFileHeader |
michael@0 | 62 | void EncodeFileHeader(); |
michael@0 | 63 | // Encodes the icon directory info header mICODirEntry |
michael@0 | 64 | void EncodeInfoHeader(); |
michael@0 | 65 | // Obtains the current offset filled up to for the image buffer |
michael@0 | 66 | inline int32_t GetCurrentImageBufferOffset() |
michael@0 | 67 | { |
michael@0 | 68 | return static_cast<int32_t>(mImageBufferCurr - mImageBufferStart); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | // Holds either a PNG or a BMP depending on the encoding options specified |
michael@0 | 72 | // or if no encoding options specified will use the default (PNG) |
michael@0 | 73 | nsCOMPtr<imgIEncoder> mContainedEncoder; |
michael@0 | 74 | |
michael@0 | 75 | // These headers will always contain endian independent stuff. |
michael@0 | 76 | // Don't trust the width and height of mICODirEntry directly, |
michael@0 | 77 | // instead use the accessors GetRealWidth() and GetRealHeight(). |
michael@0 | 78 | mozilla::image::IconFileHeader mICOFileHeader; |
michael@0 | 79 | mozilla::image::IconDirEntry mICODirEntry; |
michael@0 | 80 | |
michael@0 | 81 | // Keeps track of the start of the image buffer |
michael@0 | 82 | uint8_t* mImageBufferStart; |
michael@0 | 83 | // Keeps track of the current position in the image buffer |
michael@0 | 84 | uint8_t* mImageBufferCurr; |
michael@0 | 85 | // Keeps track of the image buffer size |
michael@0 | 86 | uint32_t mImageBufferSize; |
michael@0 | 87 | // Keeps track of the number of bytes in the image buffer which are read |
michael@0 | 88 | uint32_t mImageBufferReadPoint; |
michael@0 | 89 | // Stores true if the image is done being encoded |
michael@0 | 90 | bool mFinished; |
michael@0 | 91 | // Stores true if the contained image is a PNG |
michael@0 | 92 | bool mUsePNG; |
michael@0 | 93 | |
michael@0 | 94 | nsCOMPtr<nsIInputStreamCallback> mCallback; |
michael@0 | 95 | nsCOMPtr<nsIEventTarget> mCallbackTarget; |
michael@0 | 96 | uint32_t mNotifyThreshold; |
michael@0 | 97 | }; |