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 | /* -*- Mode: C++; tab-width: 2; 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 | #ifndef MOZILLA_IMAGELIB_EXIF_H_ |
michael@0 | 7 | #define MOZILLA_IMAGELIB_EXIF_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> |
michael@0 | 10 | #include "mozilla/TypedEnum.h" |
michael@0 | 11 | #include "nsDebug.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "Orientation.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace mozilla { |
michael@0 | 16 | namespace image { |
michael@0 | 17 | |
michael@0 | 18 | MOZ_BEGIN_ENUM_CLASS(ByteOrder, uint8_t) |
michael@0 | 19 | Unknown, |
michael@0 | 20 | LittleEndian, |
michael@0 | 21 | BigEndian |
michael@0 | 22 | MOZ_END_ENUM_CLASS(ByteOrder) |
michael@0 | 23 | |
michael@0 | 24 | struct EXIFData |
michael@0 | 25 | { |
michael@0 | 26 | EXIFData() { } |
michael@0 | 27 | explicit EXIFData(Orientation aOrientation) : orientation(aOrientation) { } |
michael@0 | 28 | |
michael@0 | 29 | const Orientation orientation; |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | class EXIFParser |
michael@0 | 33 | { |
michael@0 | 34 | public: |
michael@0 | 35 | static EXIFData |
michael@0 | 36 | Parse(const uint8_t* aData, const uint32_t aLength) |
michael@0 | 37 | { |
michael@0 | 38 | EXIFParser parser; |
michael@0 | 39 | return parser.ParseEXIF(aData, aLength); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | private: |
michael@0 | 43 | EXIFParser() |
michael@0 | 44 | : mStart(nullptr) |
michael@0 | 45 | , mCurrent(nullptr) |
michael@0 | 46 | , mLength(0) |
michael@0 | 47 | , mRemainingLength(0) |
michael@0 | 48 | , mByteOrder(ByteOrder::Unknown) |
michael@0 | 49 | { } |
michael@0 | 50 | |
michael@0 | 51 | EXIFData ParseEXIF(const uint8_t* aData, const uint32_t aLength); |
michael@0 | 52 | bool ParseEXIFHeader(); |
michael@0 | 53 | bool ParseTIFFHeader(uint32_t& aIFD0OffsetOut); |
michael@0 | 54 | bool ParseIFD0(Orientation& aOrientationOut); |
michael@0 | 55 | bool ParseOrientation(uint16_t aType, uint32_t aCount, Orientation& aOut); |
michael@0 | 56 | |
michael@0 | 57 | bool Initialize(const uint8_t* aData, const uint32_t aLength); |
michael@0 | 58 | void Advance(const uint32_t aDistance); |
michael@0 | 59 | void JumpTo(const uint32_t aOffset); |
michael@0 | 60 | |
michael@0 | 61 | bool MatchString(const char* aString, const uint32_t aLength); |
michael@0 | 62 | bool MatchUInt16(const uint16_t aValue); |
michael@0 | 63 | bool ReadUInt16(uint16_t& aOut); |
michael@0 | 64 | bool ReadUInt32(uint32_t& aOut); |
michael@0 | 65 | |
michael@0 | 66 | const uint8_t* mStart; |
michael@0 | 67 | const uint8_t* mCurrent; |
michael@0 | 68 | uint32_t mLength; |
michael@0 | 69 | uint32_t mRemainingLength; |
michael@0 | 70 | ByteOrder mByteOrder; |
michael@0 | 71 | }; |
michael@0 | 72 | |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | #endif |