Bug 1444460 [wpt PR 9948] - gyroscope: Rename LocalCoordinateSystem to GyroscopeLocal...
[gecko.git] / dom / file / BaseBlobImpl.h
blob3e084b32131c6d393d14ec40012c485590f53ddc
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"
12 namespace mozilla {
13 namespace dom {
15 class BaseBlobImpl : public BlobImpl
17 public:
18 BaseBlobImpl(const nsAString& aName, const nsAString& aContentType,
19 uint64_t aLength, int64_t aLastModifiedDate)
20 : mIsFile(true)
21 , mImmutable(false)
22 , mContentType(aContentType)
23 , mName(aName)
24 , mStart(0)
25 , mLength(aLength)
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,
34 uint64_t aLength)
35 : mIsFile(true)
36 , mImmutable(false)
37 , mContentType(aContentType)
38 , mName(aName)
39 , mStart(0)
40 , mLength(aLength)
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)
49 : mIsFile(false)
50 , mImmutable(false)
51 , mContentType(aContentType)
52 , mStart(0)
53 , mLength(aLength)
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,
62 uint64_t aLength)
63 : mIsFile(false)
64 , mImmutable(false)
65 , mContentType(aContentType)
66 , mStart(aStart)
67 , mLength(aLength)
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
95 return mLength;
98 virtual void GetType(nsAString& aType) override;
100 size_t GetAllocationSize() const override
102 return 0;
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
111 return nullptr;
114 virtual const nsTArray<RefPtr<BlobImpl>>*
115 GetSubBlobImpls() const override
117 return nullptr;
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;
137 virtual void
138 SetLazyData(const nsAString& aName, const nsAString& aContentType,
139 uint64_t aLength, int64_t aLastModifiedDate) override
141 mName = aName;
142 mContentType = aContentType;
143 mLength = aLength;
144 mLastModificationDate = aLastModifiedDate;
145 mIsFile = !aName.IsVoid();
148 virtual bool IsMemoryFile() const override
150 return false;
153 virtual bool IsDateUnknown() const override
155 return mIsFile && mLastModificationDate == INT64_MAX;
158 virtual bool IsFile() const override
160 return mIsFile;
163 virtual bool IsSizeUnknown() const override
165 return mLength == UINT64_MAX;
168 protected:
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();
178 bool mIsFile;
179 bool mImmutable;
181 nsString mContentType;
182 nsString mName;
183 nsString mPath; // The path relative to a directory chosen by the user
185 uint64_t mStart;
186 uint64_t mLength;
188 int64_t mLastModificationDate;
190 const uint64_t mSerialNumber;
193 } // namespace dom
194 } // namespace mozilla
196 #endif // mozilla_dom_BaseBlobImpl_h