image/src/imgDecoderObserver.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  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H_
     7 #define MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H_
     9 #include "nsRect.h"
    10 #include "mozilla/WeakPtr.h"
    12 struct nsIntRect;
    14 /**
    15  * imgDecoderObserver interface
    16  *
    17  * This interface is used to observe Decoder objects.
    18  *
    19  * We make the distinction here between "load" and "decode" notifications. Load
    20  * notifications are fired as the image is loaded from the network or
    21  * filesystem. Decode notifications are fired as the image is decoded. If an
    22  * image is decoded on load and not visibly discarded, decode notifications are
    23  * nested logically inside load notifications as one might expect. However, with
    24  * decode-on-draw, the set of decode notifications can come completely _after_
    25  * the load notifications, and can come multiple times if the image is
    26  * discardable. Moreover, they can be interleaved in various ways. In general,
    27  * any presumed ordering between load and decode notifications should not be
    28  * relied upon.
    29  *
    30  * Decode notifications may or may not be synchronous, depending on the
    31  * situation. If imgIDecoder::FLAG_SYNC_DECODE is passed to a function that
    32  * triggers a decode, all notifications that can be generated from the currently
    33  * loaded data fire before the call returns. If FLAG_SYNC_DECODE is not passed,
    34  * all, some, or none of the notifications may fire before the call returns.
    35  */
    36 class imgDecoderObserver
    37 {
    38 public:
    39   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(imgDecoderObserver);
    41   /**
    42    * Load notification.
    43    *
    44    * called at the same time that nsIRequestObserver::onStartRequest would be
    45    * (used only for observers of imgIRequest objects, which are nsIRequests,
    46    * not imgIDecoder objects)
    47    */
    48   virtual void OnStartRequest() = 0;
    50   /**
    51    * Decode notification.
    52    *
    53    * Called as soon as the image begins getting decoded. This does not include
    54    * "header-only" decodes used by decode-on-draw to parse the width/height
    55    * out of the image. Thus, it is a decode notification only.
    56    */
    57   virtual void OnStartDecode() = 0;
    59   /**
    60    * Load notification.
    61    *
    62    * Called once enough data has been loaded from the network that we were able
    63    * to parse the width/height from the image. By the time this callback is been
    64    * called, the size has been set on the container and STATUS_SIZE_AVAILABLE
    65    * has been set on the associated imgRequest.
    66    */
    67   virtual void OnStartContainer() = 0;
    69   /**
    70    * Decode notification.
    71    *
    72    * Called when we know a frame has begun decoding.
    73    */
    74   virtual void OnStartFrame() = 0;
    76   /**
    77    * Decode notification.
    78    *
    79    * called when there is more to paint.
    80    */
    81   virtual void FrameChanged(const nsIntRect * aDirtyRect) = 0;
    83   /**
    84    * Decode notification.
    85    *
    86    * called when a frame is finished decoding.
    87    */
    88   virtual void OnStopFrame() = 0;
    90   /**
    91    * Notification for when an image is known to be animated. This should be
    92    * fired at the earliest possible time.
    93    */
    94   virtual void OnImageIsAnimated() = 0;
    96   /**
    97    * Decode notification.
    98    *
    99    * Called when all decoding has terminated.
   100    */
   101   virtual void OnStopDecode(nsresult status) = 0;
   103   /**
   104    * Load notification.
   105    *
   106    * called at the same time that nsIRequestObserver::onStopRequest would be
   107    * (used only for observers of imgIRequest objects, which are nsIRequests,
   108    * not imgIDecoder objects)
   109    */
   110   virtual void OnStopRequest(bool aIsLastPart, nsresult aStatus) = 0;
   112   /**
   113    * Called when the decoded image data is discarded. This means that the frames
   114    * no longer exist in decoded form, and any attempt to access or draw the
   115    * image will initiate a new series of progressive decode notifications.
   116    */
   117   virtual void OnDiscard() = 0;
   119   /**
   120    * Called when we are asked to Draw an image that is not locked.
   121    */
   122   virtual void OnUnlockedDraw() = 0;
   124   /**
   125    * Called when an image is realized to be in error state.
   126    */
   127   virtual void OnError() = 0;
   129 protected:
   130   virtual ~imgDecoderObserver() = 0;
   131 };
   133 // We must define a destructor because derived classes call our destructor from
   134 // theirs.  Pure virtual destructors only requires that child classes implement
   135 // a virtual destructor, not that we can't have one too!
   136 inline imgDecoderObserver::~imgDecoderObserver()
   137 {}
   139 #endif // MOZILLA_IMAGELIB_IMGDECODEROBSERVER_H

mercurial