summaryrefslogtreecommitdiffstats
path: root/dom/file/BaseBlobImpl.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /dom/file/BaseBlobImpl.h
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/file/BaseBlobImpl.h')
-rw-r--r--dom/file/BaseBlobImpl.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/dom/file/BaseBlobImpl.h b/dom/file/BaseBlobImpl.h
new file mode 100644
index 0000000000..6332278ade
--- /dev/null
+++ b/dom/file/BaseBlobImpl.h
@@ -0,0 +1,163 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_dom_BaseBlobImpl_h
+#define mozilla_dom_BaseBlobImpl_h
+
+#include "mozilla/dom/BlobImpl.h"
+#include "mozilla/ErrorResult.h"
+
+namespace mozilla {
+namespace dom {
+
+class FileBlobImpl;
+
+class BaseBlobImpl : public BlobImpl {
+ friend class FileBlobImpl;
+
+ public:
+ // File constructor.
+ BaseBlobImpl(const nsAString& aName, const nsAString& aContentType,
+ uint64_t aLength, int64_t aLastModifiedDate)
+ : mIsFile(true),
+ mContentType(aContentType),
+ mName(aName),
+ mStart(0),
+ mLength(aLength),
+ mSerialNumber(NextSerialNumber()),
+ mLastModificationDate(aLastModifiedDate) {
+ // Ensure non-null mContentType by default
+ mContentType.SetIsVoid(false);
+ }
+
+ // Blob constructor without starting point.
+ BaseBlobImpl(const nsAString& aContentType, uint64_t aLength)
+ : mIsFile(false),
+ mContentType(aContentType),
+ mStart(0),
+ mLength(aLength),
+ mSerialNumber(NextSerialNumber()),
+ mLastModificationDate(0) {
+ // Ensure non-null mContentType by default
+ mContentType.SetIsVoid(false);
+ }
+
+ // Blob constructor with starting point.
+ BaseBlobImpl(const nsAString& aContentType, uint64_t aStart, uint64_t aLength)
+ : mIsFile(false),
+ mContentType(aContentType),
+ mStart(aStart),
+ mLength(aLength),
+ mSerialNumber(NextSerialNumber()),
+ mLastModificationDate(0) {
+ // Ensure non-null mContentType by default
+ mContentType.SetIsVoid(false);
+ }
+
+ virtual void GetName(nsAString& aName) const override;
+
+ virtual void GetDOMPath(nsAString& aName) const override;
+
+ virtual void SetDOMPath(const nsAString& aName) override;
+
+ virtual int64_t GetLastModified(ErrorResult& aRv) override;
+
+ virtual void GetMozFullPath(nsAString& aName,
+ SystemCallerGuarantee /* unused */,
+ ErrorResult& aRv) override;
+
+ virtual void GetMozFullPathInternal(nsAString& aFileName,
+ ErrorResult& aRv) override;
+
+ virtual uint64_t GetSize(ErrorResult& aRv) override { return mLength; }
+
+ virtual void GetType(nsAString& aType) override;
+
+ size_t GetAllocationSize() const override { return 0; }
+
+ size_t GetAllocationSize(
+ FallibleTArray<BlobImpl*>& aVisitedBlobImpls) const override {
+ return GetAllocationSize();
+ }
+
+ virtual uint64_t GetSerialNumber() const override { return mSerialNumber; }
+
+ virtual already_AddRefed<BlobImpl> CreateSlice(uint64_t aStart,
+ uint64_t aLength,
+ const nsAString& aContentType,
+ ErrorResult& aRv) override {
+ return nullptr;
+ }
+
+ virtual const nsTArray<RefPtr<BlobImpl>>* GetSubBlobImpls() const override {
+ return nullptr;
+ }
+
+ virtual void CreateInputStream(nsIInputStream** aStream,
+ ErrorResult& aRv) override {
+ aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
+ }
+
+ virtual int64_t GetFileId() override;
+
+ virtual void SetLazyData(const nsAString& aName,
+ const nsAString& aContentType, uint64_t aLength,
+ int64_t aLastModifiedDate) override {
+ mName = aName;
+ mContentType = aContentType;
+ mLength = aLength;
+ SetLastModificationDatePrecisely(aLastModifiedDate);
+ mIsFile = !aName.IsVoid();
+ }
+
+ virtual bool IsMemoryFile() const override { return false; }
+
+ virtual bool IsFile() const override { return mIsFile; }
+
+ virtual void GetBlobImplType(nsAString& aBlobImplType) const override {
+ aBlobImplType = u"BaseBlobImpl"_ns;
+ }
+
+ protected:
+ virtual ~BaseBlobImpl() = default;
+
+ /**
+ * Returns a new, effectively-unique serial number. This should be used
+ * by implementations to obtain a serial number for GetSerialNumber().
+ * The implementation is thread safe.
+ */
+ static uint64_t NextSerialNumber();
+
+ void SetLastModificationDate(bool aCrossOriginIsolated, int64_t aDate);
+ void SetLastModificationDatePrecisely(int64_t aDate);
+
+#ifdef DEBUG
+ bool IsLastModificationDateUnset() const {
+ return mLastModificationDate == INT64_MAX;
+ }
+#endif
+
+ const nsString mBlobImplType;
+
+ bool mIsFile;
+
+ nsString mContentType;
+ nsString mName;
+ nsString mPath; // The path relative to a directory chosen by the user
+
+ uint64_t mStart;
+ uint64_t mLength;
+
+ const uint64_t mSerialNumber;
+
+ private:
+ int64_t mLastModificationDate;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_BaseBlobImpl_h