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/. */ 6 7 #ifndef mozilla_dom_BlobImpl_h 8 #define mozilla_dom_BlobImpl_h 9 10 #include "nsISupports.h" 11 #include "nsString.h" 12 13 #define BLOBIMPL_IID \ 14 { \ 15 0xbccb3275, 0x6778, 0x4ac5, { \ 16 0xaf, 0x03, 0x90, 0xed, 0x37, 0xad, 0xdf, 0x5d \ 17 } \ 18 } 19 20 class nsIInputStream; 21 22 namespace mozilla { 23 class ErrorResult; 24 25 namespace dom { 26 27 class SystemCallerGuarantee; 28 template <typename T> 29 class Optional; 30 31 // This is the abstract class for any File backend. It must be nsISupports 32 // because this class must be ref-counted and it has to work with IPC. 33 class BlobImpl : public nsISupports { 34 public: 35 NS_DECLARE_STATIC_IID_ACCESSOR(BLOBIMPL_IID) 36 NS_DECL_THREADSAFE_ISUPPORTS 37 38 BlobImpl() = default; 39 40 virtual void GetName(nsAString& aName) const = 0; 41 42 virtual void GetDOMPath(nsAString& aName) const = 0; 43 44 virtual void SetDOMPath(const nsAString& aName) = 0; 45 46 virtual int64_t GetLastModified(ErrorResult& aRv) = 0; 47 48 virtual void GetMozFullPath(nsAString& aName, 49 SystemCallerGuarantee /* unused */, 50 ErrorResult& aRv) = 0; 51 52 virtual void GetMozFullPathInternal(nsAString& aFileName, 53 ErrorResult& aRv) = 0; 54 55 virtual uint64_t GetSize(ErrorResult& aRv) = 0; 56 57 virtual void GetType(nsAString& aType) = 0; 58 59 virtual void GetBlobImplType(nsAString& aBlobImplType) const = 0; 60 61 virtual size_t GetAllocationSize() const = 0; 62 virtual size_t GetAllocationSize( 63 FallibleTArray<BlobImpl*>& aVisitedBlobImpls) const = 0; 64 65 /** 66 * An effectively-unique serial number identifying this instance of FileImpl. 67 * 68 * Implementations should obtain a serial number from 69 * FileImplBase::NextSerialNumber(). 70 */ 71 virtual uint64_t GetSerialNumber() const = 0; 72 73 already_AddRefed<BlobImpl> Slice(const Optional<int64_t>& aStart, 74 const Optional<int64_t>& aEnd, 75 const nsAString& aContentType, 76 ErrorResult& aRv); 77 78 virtual already_AddRefed<BlobImpl> CreateSlice(uint64_t aStart, 79 uint64_t aLength, 80 const nsAString& aContentType, 81 ErrorResult& aRv) = 0; 82 83 virtual const nsTArray<RefPtr<BlobImpl>>* GetSubBlobImpls() const = 0; 84 85 virtual void CreateInputStream(nsIInputStream** aStream, 86 ErrorResult& aRv) = 0; 87 88 virtual int64_t GetFileId() = 0; 89 90 nsresult GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength, 91 nsACString& aContentType, nsACString& aCharset); 92 93 virtual void SetLazyData(const nsAString& aName, 94 const nsAString& aContentType, uint64_t aLength, 95 int64_t aLastModifiedDate) = 0; 96 97 virtual bool IsMemoryFile() const = 0; 98 99 virtual bool IsFile() const = 0; 100 101 // Returns true if the BlobImpl is backed by an nsIFile and the underlying 102 // file is a directory. IsDirectory()103 virtual bool IsDirectory() const { return false; } 104 105 protected: 106 virtual ~BlobImpl() = default; 107 }; 108 109 NS_DEFINE_STATIC_IID_ACCESSOR(BlobImpl, BLOBIMPL_IID) 110 111 } // namespace dom 112 } // namespace mozilla 113 114 #endif // mozilla_dom_BlobImpl_h 115