Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / file / File.h
blob279b91dd93699b997cdde0e488df04b4d4f44c45
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/. */
7 #ifndef mozilla_dom_File_h
8 #define mozilla_dom_File_h
10 #include "mozilla/dom/Blob.h"
12 class nsIFile;
14 namespace mozilla::dom {
16 struct ChromeFilePropertyBag;
17 struct FilePropertyBag;
18 class Promise;
20 class File final : public Blob {
21 friend class Blob;
23 public:
24 // Note: BlobImpl must be a File in order to use this method.
25 // Check impl->IsFile().
26 static File* Create(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
28 // The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
29 // freed by free so it must be allocated by malloc or something
30 // compatible with it.
31 static already_AddRefed<File> CreateMemoryFileWithLastModifiedNow(
32 nsIGlobalObject* aGlobal, void* aMemoryBuffer, uint64_t aLength,
33 const nsAString& aName, const nsAString& aContentType);
35 // You should not use this method! Please consider to use the
36 // CreateMemoryFileWithLastModifiedNow.
37 static already_AddRefed<File> CreateMemoryFileWithCustomLastModified(
38 nsIGlobalObject* aGlobal, void* aMemoryBuffer, uint64_t aLength,
39 const nsAString& aName, const nsAString& aContentType,
40 int64_t aLastModifiedDate);
42 // This method creates a BlobFileImpl for the new File object. This is
43 // thread-safe, cross-process, cross-thread as any other BlobImpl, but, when
44 // GetType() is called, it must dispatch a runnable to the main-thread in
45 // order to use nsIMIMEService.
46 // Would be nice if we try to avoid to use this method outside the
47 // main-thread to avoid extra runnables.
48 static already_AddRefed<File> CreateFromFile(nsIGlobalObject* aGlobal,
49 nsIFile* aFile);
51 static already_AddRefed<File> CreateFromFile(nsIGlobalObject* aGlobal,
52 nsIFile* aFile,
53 const nsAString& aName,
54 const nsAString& aContentType);
56 // WebIDL methods
58 JSObject* WrapObject(JSContext* cx,
59 JS::Handle<JSObject*> aGivenProto) override;
61 // File constructor
62 static already_AddRefed<File> Constructor(const GlobalObject& aGlobal,
63 const Sequence<BlobPart>& aData,
64 const nsAString& aName,
65 const FilePropertyBag& aBag,
66 ErrorResult& aRv);
68 // ChromeOnly
69 static already_AddRefed<Promise> CreateFromFileName(
70 const GlobalObject& aGlobal, const nsAString& aPath,
71 const ChromeFilePropertyBag& aBag, SystemCallerGuarantee aGuarantee,
72 ErrorResult& aRv);
74 // ChromeOnly
75 static already_AddRefed<Promise> CreateFromNsIFile(
76 const GlobalObject& aGlobal, nsIFile* aData,
77 const ChromeFilePropertyBag& aBag, SystemCallerGuarantee aGuarantee,
78 ErrorResult& aRv);
80 void GetName(nsAString& aFileName) const;
82 int64_t GetLastModified(ErrorResult& aRv);
84 void GetRelativePath(nsAString& aPath) const;
86 void GetMozFullPath(nsAString& aFilename, SystemCallerGuarantee aGuarantee,
87 ErrorResult& aRv);
89 void GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv);
91 protected:
92 bool HasFileInterface() const override { return true; }
94 private:
95 // File constructor should never be used directly. Use Blob::Create or
96 // File::Create.
97 File(nsIGlobalObject* aGlobal, BlobImpl* aImpl);
98 ~File() override;
101 } // namespace mozilla::dom
103 #endif // mozilla_dom_File_h