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