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_BlobImpl_h
8 #define mozilla_dom_BlobImpl_h
10 #include "mozilla/dom/BindingDeclarations.h"
11 #include "mozilla/ErrorResult.h"
12 #include "nsISupportsImpl.h"
15 #define BLOBIMPL_IID \
17 0xbccb3275, 0x6778, 0x4ac5, { \
18 0xaf, 0x03, 0x90, 0xed, 0x37, 0xad, 0xdf, 0x5d \
27 // This is the abstract class for any File backend. It must be nsISupports
28 // because this class must be ref-counted and it has to work with IPC.
29 class BlobImpl
: public nsISupports
{
31 NS_DECLARE_STATIC_IID_ACCESSOR(BLOBIMPL_IID
)
32 NS_DECL_THREADSAFE_ISUPPORTS
36 virtual void GetName(nsAString
& aName
) const = 0;
38 virtual void GetDOMPath(nsAString
& aName
) const = 0;
40 virtual void SetDOMPath(const nsAString
& aName
) = 0;
42 virtual int64_t GetLastModified(ErrorResult
& aRv
) = 0;
44 virtual void SetLastModified(int64_t aLastModified
) = 0;
46 virtual void GetMozFullPath(nsAString
& aName
,
47 SystemCallerGuarantee
/* unused */,
48 ErrorResult
& aRv
) = 0;
50 virtual void GetMozFullPathInternal(nsAString
& aFileName
,
51 ErrorResult
& aRv
) = 0;
53 virtual uint64_t GetSize(ErrorResult
& aRv
) = 0;
55 virtual void GetType(nsAString
& aType
) = 0;
57 virtual void GetBlobImplType(nsAString
& aBlobImplType
) const = 0;
59 virtual size_t GetAllocationSize() const = 0;
60 virtual size_t GetAllocationSize(
61 FallibleTArray
<BlobImpl
*>& aVisitedBlobImpls
) const = 0;
64 * An effectively-unique serial number identifying this instance of FileImpl.
66 * Implementations should obtain a serial number from
67 * FileImplBase::NextSerialNumber().
69 virtual uint64_t GetSerialNumber() const = 0;
71 already_AddRefed
<BlobImpl
> Slice(const Optional
<int64_t>& aStart
,
72 const Optional
<int64_t>& aEnd
,
73 const nsAString
& aContentType
,
76 virtual already_AddRefed
<BlobImpl
> CreateSlice(uint64_t aStart
,
78 const nsAString
& aContentType
,
79 ErrorResult
& aRv
) = 0;
81 virtual const nsTArray
<RefPtr
<BlobImpl
>>* GetSubBlobImpls() const = 0;
83 virtual void CreateInputStream(nsIInputStream
** aStream
,
84 ErrorResult
& aRv
) = 0;
86 virtual int64_t GetFileId() = 0;
88 virtual nsresult
GetSendInfo(nsIInputStream
** aBody
, uint64_t* aContentLength
,
89 nsACString
& aContentType
,
90 nsACString
& aCharset
) = 0;
92 virtual nsresult
GetMutable(bool* aMutable
) const = 0;
94 virtual nsresult
SetMutable(bool aMutable
) = 0;
96 virtual void SetLazyData(const nsAString
& aName
,
97 const nsAString
& aContentType
, uint64_t aLength
,
98 int64_t aLastModifiedDate
) = 0;
100 virtual bool IsMemoryFile() const = 0;
102 virtual bool IsSizeUnknown() const = 0;
104 virtual bool IsDateUnknown() const = 0;
106 virtual bool IsFile() const = 0;
108 // Returns true if the BlobImpl is backed by an nsIFile and the underlying
109 // file is a directory.
110 virtual bool IsDirectory() const { return false; }
112 // True if this implementation can be sent to other threads.
113 virtual bool MayBeClonedToOtherThreads() const { return true; }
116 virtual ~BlobImpl() {}
119 NS_DEFINE_STATIC_IID_ACCESSOR(BlobImpl
, BLOBIMPL_IID
)
122 } // namespace mozilla
124 #endif // mozilla_dom_BlobImpl_h