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_File_h
8 : #define mozilla_dom_File_h
9 :
10 : #include "mozilla/dom/Blob.h"
11 : #include "mozilla/dom/Date.h"
12 :
13 : class nsIFile;
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : struct ChromeFilePropertyBag;
19 : struct FilePropertyBag;
20 : class Promise;
21 :
22 : class File final : public Blob
23 : {
24 : friend class Blob;
25 :
26 : public:
27 : // Note: BlobImpl must be a File in order to use this method.
28 : // Check impl->IsFile().
29 : static File*
30 : Create(nsISupports* aParent, BlobImpl* aImpl);
31 :
32 : static already_AddRefed<File>
33 : Create(nsISupports* aParent, const nsAString& aName,
34 : const nsAString& aContentType, uint64_t aLength,
35 : int64_t aLastModifiedDate);
36 :
37 : // The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
38 : // freed by free so it must be allocated by malloc or something
39 : // compatible with it.
40 : static already_AddRefed<File>
41 : CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
42 : const nsAString& aName, const nsAString& aContentType,
43 : int64_t aLastModifiedDate);
44 :
45 : // This method creates a BlobFileImpl for the new File object. This is
46 : // thread-safe, cross-process, cross-thread as any other BlobImpl, but, when
47 : // GetType() is called, it must dispatch a runnable to the main-thread in
48 : // order to use nsIMIMEService.
49 : // Would be nice if we try to avoid to use this method outside the
50 : // main-thread to avoid extra runnables.
51 : static already_AddRefed<File>
52 : CreateFromFile(nsISupports* aParent, nsIFile* aFile);
53 :
54 : static already_AddRefed<File>
55 : CreateFromFile(nsISupports* aParent, nsIFile* aFile, const nsAString& aName,
56 : const nsAString& aContentType);
57 :
58 : // WebIDL methods
59 :
60 : virtual JSObject* WrapObject(JSContext *cx,
61 : JS::Handle<JSObject*> aGivenProto) override;
62 :
63 : // File constructor
64 : static already_AddRefed<File>
65 : Constructor(const GlobalObject& aGlobal,
66 : const Sequence<BlobPart>& aData,
67 : const nsAString& aName,
68 : const FilePropertyBag& aBag,
69 : ErrorResult& aRv);
70 :
71 : // ChromeOnly
72 : static already_AddRefed<Promise>
73 : CreateFromFileName(const GlobalObject& aGlobal,
74 : const nsAString& aFilePath,
75 : const ChromeFilePropertyBag& aBag,
76 : SystemCallerGuarantee aGuarantee,
77 : ErrorResult& aRv);
78 :
79 : // ChromeOnly
80 : static already_AddRefed<Promise>
81 : CreateFromNsIFile(const GlobalObject& aGlobal,
82 : nsIFile* aFile,
83 : const ChromeFilePropertyBag& aBag,
84 : SystemCallerGuarantee aGuarantee,
85 : ErrorResult& aRv);
86 :
87 : void GetName(nsAString& aName) const;
88 :
89 : int64_t GetLastModified(ErrorResult& aRv);
90 :
91 : Date GetLastModifiedDate(ErrorResult& aRv);
92 :
93 : void GetRelativePath(nsAString& aPath) const;
94 :
95 : void GetMozFullPath(nsAString& aFilename, SystemCallerGuarantee aGuarantee,
96 : ErrorResult& aRv) const;
97 :
98 : void GetMozFullPathInternal(nsAString& aName, ErrorResult& aRv) const;
99 :
100 : protected:
101 0 : virtual bool HasFileInterface() const override { return true; }
102 :
103 : private:
104 : // File constructor should never be used directly. Use Blob::Create or
105 : // File::Create.
106 : File(nsISupports* aParent, BlobImpl* aImpl);
107 : ~File();
108 : };
109 :
110 : } // namespace dom
111 : } // namespace mozilla
112 :
113 : #endif // mozilla_dom_File_h
|