image/decoders/nsJPEGDecoder.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

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.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  *
     3  * This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #ifndef nsJPEGDecoder_h__
     8 #define nsJPEGDecoder_h__
    10 #include "RasterImage.h"
    11 /* On Windows systems, RasterImage.h brings in 'windows.h', which defines INT32.
    12  * But the jpeg decoder has its own definition of INT32. To avoid build issues,
    13  * we need to undefine the version from 'windows.h'. */
    14 #undef INT32
    16 #include "Decoder.h"
    18 #include "nsAutoPtr.h"
    20 #include "nsIInputStream.h"
    21 #include "nsIPipe.h"
    22 #include "qcms.h"
    24 extern "C" {
    25 #include "jpeglib.h"
    26 }
    28 #include <setjmp.h>
    30 namespace mozilla {
    31 namespace image {
    33 typedef struct {
    34     struct jpeg_error_mgr pub;  /* "public" fields for IJG library*/
    35     jmp_buf setjmp_buffer;      /* For handling catastropic errors */
    36 } decoder_error_mgr;
    38 typedef enum {
    39     JPEG_HEADER,                          /* Reading JFIF headers */
    40     JPEG_START_DECOMPRESS,
    41     JPEG_DECOMPRESS_PROGRESSIVE,          /* Output progressive pixels */
    42     JPEG_DECOMPRESS_SEQUENTIAL,           /* Output sequential pixels */
    43     JPEG_DONE,
    44     JPEG_SINK_NON_JPEG_TRAILER,          /* Some image files have a */
    45                                          /* non-JPEG trailer */
    46     JPEG_ERROR    
    47 } jstate;
    49 class RasterImage;
    50 class Orientation;
    52 class nsJPEGDecoder : public Decoder
    53 {
    54 public:
    55   nsJPEGDecoder(RasterImage &aImage, Decoder::DecodeStyle aDecodeStyle);
    56   virtual ~nsJPEGDecoder();
    58   virtual void InitInternal();
    59   virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy);
    60   virtual void FinishInternal();
    62   virtual Telemetry::ID SpeedHistogram();
    63   void NotifyDone();
    65 protected:
    66   Orientation ReadOrientationFromEXIF();
    67   void OutputScanlines(bool* suspend);
    69 public:
    70   struct jpeg_decompress_struct mInfo;
    71   struct jpeg_source_mgr mSourceMgr;
    72   decoder_error_mgr mErr;
    73   jstate mState;
    75   uint32_t mBytesToSkip;
    77   const JOCTET *mSegment;   // The current segment we are decoding from
    78   uint32_t mSegmentLen;     // amount of data in mSegment
    80   JOCTET *mBackBuffer;
    81   uint32_t mBackBufferLen; // Offset of end of active backtrack data
    82   uint32_t mBackBufferSize; // size in bytes what mBackBuffer was created with
    83   uint32_t mBackBufferUnreadLen; // amount of data currently in mBackBuffer
    85   JOCTET  *mProfile;
    86   uint32_t mProfileLength;
    88   qcms_profile *mInProfile;
    89   qcms_transform *mTransform;
    91   bool mReading;
    93   const Decoder::DecodeStyle mDecodeStyle;
    95   uint32_t mCMSMode;
    96 };
    98 } // namespace image
    99 } // namespace mozilla
   101 #endif // nsJPEGDecoder_h__

mercurial