tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MultipartImage.h (2813B)


      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/. */
      5 
      6 #ifndef mozilla_image_MultipartImage_h
      7 #define mozilla_image_MultipartImage_h
      8 
      9 #include "ImageWrapper.h"
     10 #include "IProgressObserver.h"
     11 #include "ProgressTracker.h"
     12 
     13 namespace mozilla {
     14 namespace image {
     15 
     16 class NextPartObserver;
     17 
     18 /**
     19 * An Image wrapper that implements support for multipart/x-mixed-replace
     20 * images.
     21 */
     22 class MultipartImage : public ImageWrapper, public IProgressObserver {
     23 public:
     24  MOZ_DECLARE_REFCOUNTED_TYPENAME(MultipartImage)
     25  // We need to always declare refcounting here, because
     26  // IProgressObserver has pure-virtual refcounting.
     27  NS_DECL_ISUPPORTS_INHERITED
     28 
     29  void BeginTransitionToPart(Image* aNextPart);
     30 
     31  // Overridden ImageWrapper methods:
     32  virtual already_AddRefed<imgIContainer> Unwrap() override;
     33  virtual already_AddRefed<ProgressTracker> GetProgressTracker() override;
     34  virtual void SetProgressTracker(ProgressTracker* aTracker) override;
     35  virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
     36                                        nsIInputStream* aInStr,
     37                                        uint64_t aSourceOffset,
     38                                        uint32_t aCount) override;
     39  virtual nsresult OnImageDataComplete(nsIRequest* aRequest, nsresult aStatus,
     40                                       bool aLastPart) override;
     41 
     42  // We don't support locking or track animation consumers for individual parts,
     43  // so we override these methods to do nothing.
     44  NS_IMETHOD LockImage() override { return NS_OK; }
     45  NS_IMETHOD UnlockImage() override { return NS_OK; }
     46  virtual void IncrementAnimationConsumers() override {}
     47  virtual void DecrementAnimationConsumers() override {}
     48 #ifdef DEBUG
     49  virtual uint32_t GetAnimationConsumers() override { return 1; }
     50 #endif
     51 
     52  // Overridden IProgressObserver methods:
     53  virtual void Notify(int32_t aType, const nsIntRect* aRect = nullptr) override;
     54  virtual void OnLoadComplete(bool aLastPart) override;
     55  virtual void SetHasImage() override;
     56  virtual bool NotificationsDeferred() const override;
     57  virtual void MarkPendingNotify() override;
     58  virtual void ClearPendingNotify() override;
     59 
     60 protected:
     61  virtual ~MultipartImage();
     62 
     63 private:
     64  friend class ImageFactory;
     65  friend class NextPartObserver;
     66 
     67  explicit MultipartImage(Image* aFirstPart);
     68  void Init();
     69 
     70  void FinishTransition();
     71 
     72  RefPtr<ProgressTracker> mTracker;
     73  RefPtr<NextPartObserver> mNextPartObserver;
     74  RefPtr<Image> mNextPart;
     75  bool mPendingNotify : 1;
     76 };
     77 
     78 }  // namespace image
     79 }  // namespace mozilla
     80 
     81 #endif  // mozilla_image_MultipartImage_h