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