/src/mozilla-central/dom/file/BaseBlobImpl.h
Line | Count | Source (jump to first uncovered line) |
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_BaseBlobImpl_h |
8 | | #define mozilla_dom_BaseBlobImpl_h |
9 | | |
10 | | #include "mozilla/dom/BlobImpl.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | class BaseBlobImpl : public BlobImpl |
16 | | { |
17 | | public: |
18 | | BaseBlobImpl(const nsAString& aName, const nsAString& aContentType, |
19 | | uint64_t aLength, int64_t aLastModifiedDate) |
20 | | : mIsFile(true) |
21 | | , mImmutable(false) |
22 | | , mContentType(aContentType) |
23 | | , mName(aName) |
24 | | , mStart(0) |
25 | | , mLength(aLength) |
26 | | , mLastModificationDate(aLastModifiedDate) |
27 | | , mSerialNumber(NextSerialNumber()) |
28 | 0 | { |
29 | 0 | // Ensure non-null mContentType by default |
30 | 0 | mContentType.SetIsVoid(false); |
31 | 0 | } |
32 | | |
33 | | BaseBlobImpl(const nsAString& aName, const nsAString& aContentType, |
34 | | uint64_t aLength) |
35 | | : mIsFile(true) |
36 | | , mImmutable(false) |
37 | | , mContentType(aContentType) |
38 | | , mName(aName) |
39 | | , mStart(0) |
40 | | , mLength(aLength) |
41 | | , mLastModificationDate(INT64_MAX) |
42 | | , mSerialNumber(NextSerialNumber()) |
43 | 0 | { |
44 | 0 | // Ensure non-null mContentType by default |
45 | 0 | mContentType.SetIsVoid(false); |
46 | 0 | } |
47 | | |
48 | | BaseBlobImpl(const nsAString& aContentType, uint64_t aLength) |
49 | | : mIsFile(false) |
50 | | , mImmutable(false) |
51 | | , mContentType(aContentType) |
52 | | , mStart(0) |
53 | | , mLength(aLength) |
54 | | , mLastModificationDate(INT64_MAX) |
55 | | , mSerialNumber(NextSerialNumber()) |
56 | 0 | { |
57 | 0 | // Ensure non-null mContentType by default |
58 | 0 | mContentType.SetIsVoid(false); |
59 | 0 | } |
60 | | |
61 | | BaseBlobImpl(const nsAString& aContentType, uint64_t aStart, |
62 | | uint64_t aLength) |
63 | | : mIsFile(false) |
64 | | , mImmutable(false) |
65 | | , mContentType(aContentType) |
66 | | , mStart(aStart) |
67 | | , mLength(aLength) |
68 | | , mLastModificationDate(INT64_MAX) |
69 | | , mSerialNumber(NextSerialNumber()) |
70 | 0 | { |
71 | 0 | MOZ_ASSERT(aLength != UINT64_MAX, "Must know length when creating slice"); |
72 | 0 | // Ensure non-null mContentType by default |
73 | 0 | mContentType.SetIsVoid(false); |
74 | 0 | } |
75 | | |
76 | | virtual void GetName(nsAString& aName) const override; |
77 | | |
78 | | virtual void GetDOMPath(nsAString& aName) const override; |
79 | | |
80 | | virtual void SetDOMPath(const nsAString& aName) override; |
81 | | |
82 | | virtual int64_t GetLastModified(ErrorResult& aRv) override; |
83 | | |
84 | | virtual void SetLastModified(int64_t aLastModified) override; |
85 | | |
86 | | virtual void GetMozFullPath(nsAString& aName, |
87 | | SystemCallerGuarantee /* unused */, |
88 | | ErrorResult& aRv) const override; |
89 | | |
90 | | virtual void GetMozFullPathInternal(nsAString& aFileName, |
91 | | ErrorResult& aRv) const override; |
92 | | |
93 | | virtual uint64_t GetSize(ErrorResult& aRv) override |
94 | 0 | { |
95 | 0 | return mLength; |
96 | 0 | } |
97 | | |
98 | | virtual void GetType(nsAString& aType) override; |
99 | | |
100 | | size_t GetAllocationSize() const override |
101 | 0 | { |
102 | 0 | return 0; |
103 | 0 | } |
104 | | |
105 | | size_t GetAllocationSize(FallibleTArray<BlobImpl*>& aVisitedBlobImpls) const override |
106 | 0 | { |
107 | 0 | return GetAllocationSize(); |
108 | 0 | } |
109 | | |
110 | 0 | virtual uint64_t GetSerialNumber() const override { return mSerialNumber; } |
111 | | |
112 | | virtual already_AddRefed<BlobImpl> |
113 | | CreateSlice(uint64_t aStart, uint64_t aLength, |
114 | | const nsAString& aContentType, ErrorResult& aRv) override |
115 | 0 | { |
116 | 0 | return nullptr; |
117 | 0 | } |
118 | | |
119 | | virtual const nsTArray<RefPtr<BlobImpl>>* |
120 | | GetSubBlobImpls() const override |
121 | 0 | { |
122 | 0 | return nullptr; |
123 | 0 | } |
124 | | |
125 | | virtual void CreateInputStream(nsIInputStream** aStream, |
126 | | ErrorResult& aRv) override |
127 | 0 | { |
128 | 0 | aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); |
129 | 0 | } |
130 | | |
131 | | virtual int64_t GetFileId() override; |
132 | | |
133 | | virtual nsresult GetSendInfo(nsIInputStream** aBody, |
134 | | uint64_t* aContentLength, |
135 | | nsACString& aContentType, |
136 | | nsACString& aCharset) override; |
137 | | |
138 | | virtual nsresult GetMutable(bool* aMutable) const override; |
139 | | |
140 | | virtual nsresult SetMutable(bool aMutable) override; |
141 | | |
142 | | virtual void |
143 | | SetLazyData(const nsAString& aName, const nsAString& aContentType, |
144 | | uint64_t aLength, int64_t aLastModifiedDate) override |
145 | 0 | { |
146 | 0 | mName = aName; |
147 | 0 | mContentType = aContentType; |
148 | 0 | mLength = aLength; |
149 | 0 | mLastModificationDate = aLastModifiedDate; |
150 | 0 | mIsFile = !aName.IsVoid(); |
151 | 0 | } |
152 | | |
153 | | virtual bool IsMemoryFile() const override |
154 | 0 | { |
155 | 0 | return false; |
156 | 0 | } |
157 | | |
158 | | virtual bool IsDateUnknown() const override |
159 | 0 | { |
160 | 0 | return mIsFile && mLastModificationDate == INT64_MAX; |
161 | 0 | } |
162 | | |
163 | | virtual bool IsFile() const override |
164 | 0 | { |
165 | 0 | return mIsFile; |
166 | 0 | } |
167 | | |
168 | | virtual bool IsSizeUnknown() const override |
169 | 0 | { |
170 | 0 | return mLength == UINT64_MAX; |
171 | 0 | } |
172 | | |
173 | | protected: |
174 | 0 | virtual ~BaseBlobImpl() {} |
175 | | |
176 | | /** |
177 | | * Returns a new, effectively-unique serial number. This should be used |
178 | | * by implementations to obtain a serial number for GetSerialNumber(). |
179 | | * The implementation is thread safe. |
180 | | */ |
181 | | static uint64_t NextSerialNumber(); |
182 | | |
183 | | bool mIsFile; |
184 | | bool mImmutable; |
185 | | |
186 | | nsString mContentType; |
187 | | nsString mName; |
188 | | nsString mPath; // The path relative to a directory chosen by the user |
189 | | |
190 | | uint64_t mStart; |
191 | | uint64_t mLength; |
192 | | |
193 | | int64_t mLastModificationDate; |
194 | | |
195 | | const uint64_t mSerialNumber; |
196 | | }; |
197 | | |
198 | | } // namespace dom |
199 | | } // namespace mozilla |
200 | | |
201 | | #endif // mozilla_dom_BaseBlobImpl_h |