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_FileBlobImpl_h
8 : #define mozilla_dom_FileBlobImpl_h
9 :
10 : #include "mozilla/dom/BaseBlobImpl.h"
11 :
12 : class nsIFile;
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : class FileBlobImpl : public BaseBlobImpl
18 : {
19 : public:
20 : NS_DECL_ISUPPORTS_INHERITED
21 :
22 : // Create as a file
23 : explicit FileBlobImpl(nsIFile* aFile);
24 :
25 : // Create as a file
26 : FileBlobImpl(const nsAString& aName, const nsAString& aContentType,
27 : uint64_t aLength, nsIFile* aFile);
28 :
29 : FileBlobImpl(const nsAString& aName, const nsAString& aContentType,
30 : uint64_t aLength, nsIFile* aFile,
31 : int64_t aLastModificationDate);
32 :
33 : // Create as a file with custom name
34 : FileBlobImpl(nsIFile* aFile, const nsAString& aName,
35 : const nsAString& aContentType);
36 :
37 : // Overrides
38 : virtual uint64_t GetSize(ErrorResult& aRv) override;
39 : virtual void GetType(nsAString& aType) override;
40 : virtual int64_t GetLastModified(ErrorResult& aRv) override;
41 : virtual void SetLastModified(int64_t aLastModified) override;
42 : virtual void GetMozFullPathInternal(nsAString& aFullPath,
43 : ErrorResult& aRv) const override;
44 : virtual void GetInternalStream(nsIInputStream** aInputStream,
45 : ErrorResult& aRv) override;
46 :
47 : virtual bool IsDirectory() const override;
48 :
49 : // We always have size and date for this kind of blob.
50 0 : virtual bool IsSizeUnknown() const override { return false; }
51 0 : virtual bool IsDateUnknown() const override { return false; }
52 :
53 0 : void SetName(const nsAString& aName)
54 : {
55 0 : mName = aName;
56 0 : }
57 :
58 0 : void SetType(const nsAString& aType)
59 : {
60 0 : mContentType = aType;
61 0 : }
62 :
63 0 : int64_t GetFileId() override
64 : {
65 0 : return mFileId;
66 : }
67 :
68 0 : void SetFileId(int64_t aFileId)
69 : {
70 0 : mFileId = aFileId;
71 0 : }
72 :
73 : protected:
74 0 : virtual ~FileBlobImpl() = default;
75 :
76 : private:
77 : // Create slice
78 : FileBlobImpl(const FileBlobImpl* aOther, uint64_t aStart,
79 : uint64_t aLength, const nsAString& aContentType);
80 :
81 : virtual already_AddRefed<BlobImpl>
82 : CreateSlice(uint64_t aStart, uint64_t aLength,
83 : const nsAString& aContentType, ErrorResult& aRv) override;
84 :
85 : nsCOMPtr<nsIFile> mFile;
86 : bool mWholeFile;
87 : int64_t mFileId;
88 : };
89 :
90 : } // namespace dom
91 : } // namespace mozilla
92 :
93 : #endif // mozilla_dom_FileBlobImpl_h
|