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_FilePickerParent_h
8 #define mozilla_dom_FilePickerParent_h
10 #include "nsIEventTarget.h"
11 #include "nsIFilePicker.h"
12 #include "nsCOMArray.h"
13 #include "nsThreadUtils.h"
14 #include "mozilla/dom/File.h"
15 #include "mozilla/dom/PFilePickerParent.h"
19 namespace mozilla::dom
{
21 class FilePickerParent
: public PFilePickerParent
{
23 FilePickerParent(const nsString
& aTitle
, const nsIFilePicker::Mode
& aMode
)
24 : mTitle(aTitle
), mMode(aMode
), mResult(nsIFilePicker::returnOK
) {}
27 virtual ~FilePickerParent();
30 NS_INLINE_DECL_REFCOUNTING(FilePickerParent
, final
)
32 void Done(nsIFilePicker::ResultCode aResult
);
34 struct BlobImplOrString
{
35 RefPtr
<BlobImpl
> mBlobImpl
;
36 nsString mDirectoryPath
;
38 enum { eBlobImpl
, eDirectoryPath
} mType
;
41 void SendFilesOrDirectories(const nsTArray
<BlobImplOrString
>& aData
);
43 mozilla::ipc::IPCResult
RecvOpen(
44 const int16_t& aSelectedType
, const bool& aAddToRecentDocs
,
45 const nsString
& aDefaultFile
, const nsString
& aDefaultExtension
,
46 nsTArray
<nsString
>&& aFilters
, nsTArray
<nsString
>&& aFilterNames
,
47 nsTArray
<nsString
>&& aRawFilters
, const nsString
& aDisplayDirectory
,
48 const nsString
& aDisplaySpecialDirectory
, const nsString
& aOkButtonLabel
,
49 const nsIFilePicker::CaptureTarget
& aCapture
);
51 mozilla::ipc::IPCResult
RecvClose();
53 virtual void ActorDestroy(ActorDestroyReason aWhy
) override
;
55 class FilePickerShownCallback
: public nsIFilePickerShownCallback
{
57 explicit FilePickerShownCallback(FilePickerParent
* aFilePickerParent
)
58 : mFilePickerParent(aFilePickerParent
) {}
61 NS_DECL_NSIFILEPICKERSHOWNCALLBACK
66 virtual ~FilePickerShownCallback() = default;
67 RefPtr
<FilePickerParent
> mFilePickerParent
;
71 bool CreateFilePicker();
73 // This runnable is used to do some I/O operation on a separate thread.
74 class IORunnable
: public Runnable
{
75 RefPtr
<FilePickerParent
> mFilePickerParent
;
76 nsTArray
<nsCOMPtr
<nsIFile
>> mFiles
;
77 nsTArray
<BlobImplOrString
> mResults
;
78 nsCOMPtr
<nsIEventTarget
> mEventTarget
;
82 IORunnable(FilePickerParent
* aFPParent
,
83 nsTArray
<nsCOMPtr
<nsIFile
>>&& aFiles
, bool aIsDirectory
);
86 NS_IMETHOD
Run() override
;
90 RefPtr
<IORunnable
> mRunnable
;
91 RefPtr
<FilePickerShownCallback
> mCallback
;
92 nsCOMPtr
<nsIFilePicker
> mFilePicker
;
95 nsIFilePicker::Mode mMode
;
96 nsIFilePicker::ResultCode mResult
;
99 } // namespace mozilla::dom
101 #endif // mozilla_dom_FilePickerParent_h