tor-browser

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

ImageWrapper.h (2460B)


      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_ImageWrapper_h
      7 #define mozilla_image_ImageWrapper_h
      8 
      9 #include "mozilla/MemoryReporting.h"
     10 #include "Image.h"
     11 
     12 namespace mozilla {
     13 namespace image {
     14 
     15 /**
     16 * Abstract superclass for Images that wrap other Images.
     17 */
     18 class ImageWrapper : public Image {
     19 public:
     20  NS_DECL_ISUPPORTS
     21  NS_DECL_IMGICONTAINER
     22 
     23  // Inherited methods from Image.
     24  virtual already_AddRefed<ProgressTracker> GetProgressTracker() override;
     25 
     26  virtual size_t SizeOfSourceWithComputedFallback(
     27      SizeOfState& aState) const override;
     28  virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
     29                                     MallocSizeOf aMallocSizeOf) const override;
     30 
     31  virtual void IncrementAnimationConsumers() override;
     32  virtual void DecrementAnimationConsumers() override;
     33 #ifdef DEBUG
     34  virtual uint32_t GetAnimationConsumers() override;
     35 #endif
     36 
     37  virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
     38                                        nsIInputStream* aInStr,
     39                                        uint64_t aSourceOffset,
     40                                        uint32_t aCount) override;
     41  virtual nsresult OnImageDataComplete(nsIRequest* aRequest, nsresult aStatus,
     42                                       bool aLastPart) override;
     43 
     44  virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override;
     45 
     46  virtual void SetInnerWindowID(uint64_t aInnerWindowId) override;
     47  virtual uint64_t InnerWindowID() const override;
     48 
     49  virtual bool HasError() override;
     50  virtual void SetHasError() override;
     51 
     52  nsIURI* GetURI() const override;
     53 
     54 protected:
     55  explicit ImageWrapper(Image* aInnerImage) : mInnerImage(aInnerImage) {
     56    MOZ_ASSERT(aInnerImage, "Need an image to wrap");
     57  }
     58 
     59  virtual ~ImageWrapper() {}
     60 
     61  /**
     62   * Returns a weak reference to the inner image wrapped by this ImageWrapper.
     63   */
     64  Image* InnerImage() const { return mInnerImage.get(); }
     65 
     66  void SetInnerImage(Image* aInnerImage) {
     67    MOZ_ASSERT(aInnerImage, "Need an image to wrap");
     68    mInnerImage = aInnerImage;
     69  }
     70 
     71 private:
     72  RefPtr<Image> mInnerImage;
     73 };
     74 
     75 }  // namespace image
     76 }  // namespace mozilla
     77 
     78 #endif  // mozilla_image_ImageWrapper_h