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
{
18 class BaseBlobImpl
: public BlobImpl
{
19 friend class FileBlobImpl
;
23 BaseBlobImpl(const nsAString
& aName
, const nsAString
& aContentType
,
24 uint64_t aLength
, int64_t aLastModifiedDate
)
26 mContentType(aContentType
),
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
)
39 mContentType(aContentType
),
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
)
51 mContentType(aContentType
),
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
{
92 const nsTArray
<RefPtr
<BlobImpl
>>* GetSubBlobImpls() const override
{
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
{
106 mContentType
= aContentType
;
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
;
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
);
134 bool IsLastModificationDateUnset() const {
135 return mLastModificationDate
== INT64_MAX
;
139 const nsString mBlobImplType
;
143 nsString mContentType
;
145 nsString mPath
; // The path relative to a directory chosen by the user
150 const uint64_t mSerialNumber
;
153 int64_t mLastModificationDate
;
156 } // namespace mozilla::dom
158 #endif // mozilla_dom_BaseBlobImpl_h