MultipartImage.h 3.0 KB

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