Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/MultipartImage.h
Line
Count
Source (jump to first uncovered line)
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
23
  : public ImageWrapper
24
  , public IProgressObserver
25
{
26
public:
27
  MOZ_DECLARE_REFCOUNTED_TYPENAME(MultipartImage)
28
  // We need to always declare refcounting here, because
29
  // IProgressObserver has pure-virtual refcounting.
30
  NS_DECL_ISUPPORTS_INHERITED
31
32
  void BeginTransitionToPart(Image* aNextPart);
33
34
  // Overridden ImageWrapper methods:
35
  virtual already_AddRefed<imgIContainer> Unwrap() override;
36
  virtual already_AddRefed<ProgressTracker> GetProgressTracker() override;
37
  virtual void SetProgressTracker(ProgressTracker* aTracker) override;
38
  virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
39
                                        nsISupports* aContext,
40
                                        nsIInputStream* aInStr,
41
                                        uint64_t aSourceOffset,
42
                                        uint32_t aCount) override;
43
  virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
44
                                       nsISupports* aContext,
45
                                       nsresult aStatus,
46
                                       bool aLastPart) override;
47
48
  // We don't support locking or track animation consumers for individual parts,
49
  // so we override these methods to do nothing.
50
0
  NS_IMETHOD LockImage() override { return NS_OK; }
51
0
  NS_IMETHOD UnlockImage() override { return NS_OK; }
52
0
  virtual void IncrementAnimationConsumers() override { }
53
0
  virtual void DecrementAnimationConsumers() override { }
54
#ifdef DEBUG
55
  virtual uint32_t GetAnimationConsumers() override { return 1; }
56
#endif
57
58
  // Overridden IProgressObserver methods:
59
  virtual void Notify(int32_t aType,
60
                      const nsIntRect* aRect = nullptr) override;
61
  virtual void OnLoadComplete(bool aLastPart) override;
62
  virtual void SetHasImage() override;
63
  virtual bool NotificationsDeferred() const override;
64
  virtual void MarkPendingNotify() override;
65
  virtual void ClearPendingNotify() override;
66
67
protected:
68
  virtual ~MultipartImage();
69
70
private:
71
  friend class ImageFactory;
72
  friend class NextPartObserver;
73
74
  explicit MultipartImage(Image* aFirstPart);
75
  void Init();
76
77
  void FinishTransition();
78
79
  RefPtr<ProgressTracker> mTracker;
80
  RefPtr<NextPartObserver> mNextPartObserver;
81
  RefPtr<Image> mNextPart;
82
  bool mPendingNotify : 1;
83
};
84
85
} // namespace image
86
} // namespace mozilla
87
88
#endif // mozilla_image_MultipartImage_h