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 "mozilla/dom/BlobImpl.h"
15 class BaseBlobImpl
: public BlobImpl
18 BaseBlobImpl(const nsAString
& aName
, const nsAString
& aContentType
,
19 uint64_t aLength
, int64_t aLastModifiedDate
)
22 , mContentType(aContentType
)
26 , mLastModificationDate(aLastModifiedDate
)
27 , mSerialNumber(NextSerialNumber())
29 // Ensure non-null mContentType by default
30 mContentType
.SetIsVoid(false);
33 BaseBlobImpl(const nsAString
& aName
, const nsAString
& aContentType
,
37 , mContentType(aContentType
)
41 , mLastModificationDate(INT64_MAX
)
42 , mSerialNumber(NextSerialNumber())
44 // Ensure non-null mContentType by default
45 mContentType
.SetIsVoid(false);
48 BaseBlobImpl(const nsAString
& aContentType
, uint64_t aLength
)
51 , mContentType(aContentType
)
54 , mLastModificationDate(INT64_MAX
)
55 , mSerialNumber(NextSerialNumber())
57 // Ensure non-null mContentType by default
58 mContentType
.SetIsVoid(false);
61 BaseBlobImpl(const nsAString
& aContentType
, uint64_t aStart
,
65 , mContentType(aContentType
)
68 , mLastModificationDate(INT64_MAX
)
69 , mSerialNumber(NextSerialNumber())
71 MOZ_ASSERT(aLength
!= UINT64_MAX
, "Must know length when creating slice");
72 // Ensure non-null mContentType by default
73 mContentType
.SetIsVoid(false);
76 virtual void GetName(nsAString
& aName
) const override
;
78 virtual void GetDOMPath(nsAString
& aName
) const override
;
80 virtual void SetDOMPath(const nsAString
& aName
) override
;
82 virtual int64_t GetLastModified(ErrorResult
& aRv
) override
;
84 virtual void SetLastModified(int64_t aLastModified
) override
;
86 virtual void GetMozFullPath(nsAString
& aName
,
87 SystemCallerGuarantee
/* unused */,
88 ErrorResult
& aRv
) const override
;
90 virtual void GetMozFullPathInternal(nsAString
& aFileName
,
91 ErrorResult
& aRv
) const override
;
93 virtual uint64_t GetSize(ErrorResult
& aRv
) override
98 virtual void GetType(nsAString
& aType
) override
;
100 size_t GetAllocationSize() const override
105 virtual uint64_t GetSerialNumber() const override
{ return mSerialNumber
; }
107 virtual already_AddRefed
<BlobImpl
>
108 CreateSlice(uint64_t aStart
, uint64_t aLength
,
109 const nsAString
& aContentType
, ErrorResult
& aRv
) override
114 virtual const nsTArray
<RefPtr
<BlobImpl
>>*
115 GetSubBlobImpls() const override
120 virtual void CreateInputStream(nsIInputStream
** aStream
,
121 ErrorResult
& aRv
) override
123 aRv
.Throw(NS_ERROR_NOT_IMPLEMENTED
);
126 virtual int64_t GetFileId() override
;
128 virtual nsresult
GetSendInfo(nsIInputStream
** aBody
,
129 uint64_t* aContentLength
,
130 nsACString
& aContentType
,
131 nsACString
& aCharset
) override
;
133 virtual nsresult
GetMutable(bool* aMutable
) const override
;
135 virtual nsresult
SetMutable(bool aMutable
) override
;
138 SetLazyData(const nsAString
& aName
, const nsAString
& aContentType
,
139 uint64_t aLength
, int64_t aLastModifiedDate
) override
142 mContentType
= aContentType
;
144 mLastModificationDate
= aLastModifiedDate
;
145 mIsFile
= !aName
.IsVoid();
148 virtual bool IsMemoryFile() const override
153 virtual bool IsDateUnknown() const override
155 return mIsFile
&& mLastModificationDate
== INT64_MAX
;
158 virtual bool IsFile() const override
163 virtual bool IsSizeUnknown() const override
165 return mLength
== UINT64_MAX
;
169 virtual ~BaseBlobImpl() {}
172 * Returns a new, effectively-unique serial number. This should be used
173 * by implementations to obtain a serial number for GetSerialNumber().
174 * The implementation is thread safe.
176 static uint64_t NextSerialNumber();
181 nsString mContentType
;
183 nsString mPath
; // The path relative to a directory chosen by the user
188 int64_t mLastModificationDate
;
190 const uint64_t mSerialNumber
;
194 } // namespace mozilla
196 #endif // mozilla_dom_BaseBlobImpl_h