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"
14 namespace mozilla::dom
{
16 struct ChromeFilePropertyBag
;
17 struct FilePropertyBag
;
20 class File final
: public Blob
{
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
,
51 static already_AddRefed
<File
> CreateFromFile(nsIGlobalObject
* aGlobal
,
53 const nsAString
& aName
,
54 const nsAString
& aContentType
);
58 JSObject
* WrapObject(JSContext
* cx
,
59 JS::Handle
<JSObject
*> aGivenProto
) override
;
62 static already_AddRefed
<File
> Constructor(const GlobalObject
& aGlobal
,
63 const Sequence
<BlobPart
>& aData
,
64 const nsAString
& aName
,
65 const FilePropertyBag
& aBag
,
69 static already_AddRefed
<Promise
> CreateFromFileName(
70 const GlobalObject
& aGlobal
, const nsAString
& aPath
,
71 const ChromeFilePropertyBag
& aBag
, SystemCallerGuarantee aGuarantee
,
75 static already_AddRefed
<Promise
> CreateFromNsIFile(
76 const GlobalObject
& aGlobal
, nsIFile
* aData
,
77 const ChromeFilePropertyBag
& aBag
, SystemCallerGuarantee aGuarantee
,
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
,
89 void GetMozFullPathInternal(nsAString
& aFileName
, ErrorResult
& aRv
);
92 bool HasFileInterface() const override
{ return true; }
95 // File constructor should never be used directly. Use Blob::Create or
97 File(nsIGlobalObject
* aGlobal
, BlobImpl
* aImpl
);
101 } // namespace mozilla::dom
103 #endif // mozilla_dom_File_h