Bug 1857841 - pt 3. Add a new page kind named "fresh" r=glandium
[gecko.git] / dom / file / BaseBlobImpl.h
blob7265fc21045d989735da7c2dc8d8b391de1d218e
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_BaseBlobImpl_h
8 #define mozilla_dom_BaseBlobImpl_h
10 #include "nsIGlobalObject.h"
11 #include "mozilla/dom/BlobImpl.h"
12 #include "mozilla/ErrorResult.h"
14 namespace mozilla::dom {
16 class FileBlobImpl;
18 class BaseBlobImpl : public BlobImpl {
19 friend class FileBlobImpl;
21 public:
22 // File constructor.
23 BaseBlobImpl(const nsAString& aName, const nsAString& aContentType,
24 uint64_t aLength, int64_t aLastModifiedDate)
25 : mIsFile(true),
26 mContentType(aContentType),
27 mName(aName),
28 mStart(0),
29 mLength(aLength),
30 mSerialNumber(NextSerialNumber()),
31 mLastModificationDate(aLastModifiedDate) {
32 // Ensure non-null mContentType by default
33 mContentType.SetIsVoid(false);
36 // Blob constructor without starting point.
37 BaseBlobImpl(const nsAString& aContentType, uint64_t aLength)
38 : mIsFile(false),
39 mContentType(aContentType),
40 mStart(0),
41 mLength(aLength),
42 mSerialNumber(NextSerialNumber()),
43 mLastModificationDate(0) {
44 // Ensure non-null mContentType by default
45 mContentType.SetIsVoid(false);
48 // Blob constructor with starting point.
49 BaseBlobImpl(const nsAString& aContentType, uint64_t aStart, uint64_t aLength)
50 : mIsFile(false),
51 mContentType(aContentType),
52 mStart(aStart),
53 mLength(aLength),
54 mSerialNumber(NextSerialNumber()),
55 mLastModificationDate(0) {
56 // Ensure non-null mContentType by default
57 mContentType.SetIsVoid(false);
60 void GetName(nsAString& aName) const override;
62 void GetDOMPath(nsAString& aPath) const override;
64 void SetDOMPath(const nsAString& aPath) override;
66 int64_t GetLastModified(ErrorResult& aRv) override;
68 void GetMozFullPath(nsAString& aFileName, SystemCallerGuarantee /* unused */,
69 ErrorResult& aRv) override;
71 void GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv) override;
73 uint64_t GetSize(ErrorResult& aRv) override { return mLength; }
75 void GetType(nsAString& aType) override;
77 size_t GetAllocationSize() const override { return 0; }
79 size_t GetAllocationSize(
80 FallibleTArray<BlobImpl*>& aVisitedBlobImpls) const override {
81 return GetAllocationSize();
84 uint64_t GetSerialNumber() const override { return mSerialNumber; }
86 already_AddRefed<BlobImpl> CreateSlice(uint64_t aStart, uint64_t aLength,
87 const nsAString& aContentType,
88 ErrorResult& aRv) const override {
89 return nullptr;
92 const nsTArray<RefPtr<BlobImpl>>* GetSubBlobImpls() const override {
93 return nullptr;
96 void CreateInputStream(nsIInputStream** aStream,
97 ErrorResult& aRv) const override {
98 aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
101 int64_t GetFileId() const override;
103 void SetLazyData(const nsAString& aName, const nsAString& aContentType,
104 uint64_t aLength, int64_t aLastModifiedDate) override {
105 mName = aName;
106 mContentType = aContentType;
107 mLength = aLength;
108 SetLastModificationDatePrecisely(aLastModifiedDate);
109 mIsFile = !aName.IsVoid();
112 bool IsMemoryFile() const override { return false; }
114 bool IsFile() const override { return mIsFile; }
116 void GetBlobImplType(nsAString& aBlobImplType) const override {
117 aBlobImplType = u"BaseBlobImpl"_ns;
120 protected:
121 ~BaseBlobImpl() override = default;
124 * Returns a new, effectively-unique serial number. This should be used
125 * by implementations to obtain a serial number for GetSerialNumber().
126 * The implementation is thread safe.
128 static uint64_t NextSerialNumber();
130 void SetLastModificationDate(RTPCallerType aRTPCallerType, int64_t aDate);
131 void SetLastModificationDatePrecisely(int64_t aDate);
133 #ifdef DEBUG
134 bool IsLastModificationDateUnset() const {
135 return mLastModificationDate == INT64_MAX;
137 #endif
139 const nsString mBlobImplType;
141 bool mIsFile;
143 nsString mContentType;
144 nsString mName;
145 nsString mPath; // The path relative to a directory chosen by the user
147 uint64_t mStart;
148 uint64_t mLength;
150 const uint64_t mSerialNumber;
152 private:
153 int64_t mLastModificationDate;
156 } // namespace mozilla::dom
158 #endif // mozilla_dom_BaseBlobImpl_h