2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2014-02-18 04:30:06 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_FilePickerParent_h
|
|
|
|
#define mozilla_dom_FilePickerParent_h
|
|
|
|
|
2014-02-25 01:09:03 +04:00
|
|
|
#include "nsIEventTarget.h"
|
2014-02-18 04:30:06 +04:00
|
|
|
#include "nsIFilePicker.h"
|
2014-02-25 01:09:03 +04:00
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2015-03-19 00:21:02 +03:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-02-18 04:30:06 +04:00
|
|
|
#include "mozilla/dom/PFilePickerParent.h"
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
class nsIFile;
|
|
|
|
|
2014-02-18 04:30:06 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class FilePickerParent : public PFilePickerParent {
|
|
|
|
public:
|
2018-04-13 16:01:28 +03:00
|
|
|
FilePickerParent(const nsString& aTitle, const int16_t& aMode)
|
2018-06-16 17:21:46 +03:00
|
|
|
: mTitle(aTitle), mMode(aMode), mResult(nsIFilePicker::returnOK) {}
|
2018-04-13 16:01:28 +03:00
|
|
|
|
|
|
|
virtual ~FilePickerParent();
|
|
|
|
|
|
|
|
void Done(int16_t aResult);
|
|
|
|
|
|
|
|
struct BlobImplOrString {
|
|
|
|
RefPtr<BlobImpl> mBlobImpl;
|
|
|
|
nsString mDirectoryPath;
|
|
|
|
|
|
|
|
enum { eBlobImpl, eDirectoryPath } mType;
|
2016-03-20 13:56:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void SendFilesOrDirectories(const nsTArray<BlobImplOrString>& aData);
|
2014-02-18 04:30:06 +04:00
|
|
|
|
2019-07-10 06:27:27 +03:00
|
|
|
mozilla::ipc::IPCResult RecvOpen(
|
|
|
|
const int16_t& aSelectedType, const bool& aAddToRecentDocs,
|
|
|
|
const nsString& aDefaultFile, const nsString& aDefaultExtension,
|
|
|
|
nsTArray<nsString>&& aFilters, nsTArray<nsString>&& aFilterNames,
|
|
|
|
nsTArray<nsString>&& aRawFilters, const nsString& aDisplayDirectory,
|
2019-07-30 21:13:05 +03:00
|
|
|
const nsString& aDisplaySpecialDirectory, const nsString& aOkButtonLabel,
|
|
|
|
const int16_t& aCapture);
|
2014-02-18 04:30:06 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
2014-02-18 04:30:06 +04:00
|
|
|
|
|
|
|
class FilePickerShownCallback : public nsIFilePickerShownCallback {
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit FilePickerShownCallback(FilePickerParent* aFilePickerParent)
|
2014-02-18 04:30:06 +04:00
|
|
|
: mFilePickerParent(aFilePickerParent) {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIFILEPICKERSHOWNCALLBACK
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
private:
|
2014-06-23 23:56:07 +04:00
|
|
|
virtual ~FilePickerShownCallback() {}
|
2014-02-18 04:30:06 +04:00
|
|
|
FilePickerParent* mFilePickerParent;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool CreateFilePicker();
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
// This runnable is used to do some I/O operation on a separate thread.
|
2016-04-26 03:23:21 +03:00
|
|
|
class IORunnable : public Runnable {
|
2014-02-25 01:09:03 +04:00
|
|
|
FilePickerParent* mFilePickerParent;
|
2016-03-20 13:56:10 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIFile>> mFiles;
|
|
|
|
nsTArray<BlobImplOrString> mResults;
|
2014-02-25 01:09:03 +04:00
|
|
|
nsCOMPtr<nsIEventTarget> mEventTarget;
|
2016-03-20 13:56:10 +03:00
|
|
|
bool mIsDirectory;
|
2014-02-25 01:09:03 +04:00
|
|
|
|
|
|
|
public:
|
2016-03-20 13:56:10 +03:00
|
|
|
IORunnable(FilePickerParent* aFPParent, nsTArray<nsCOMPtr<nsIFile>>& aFiles,
|
|
|
|
bool aIsDirectory);
|
|
|
|
|
2014-02-25 01:09:03 +04:00
|
|
|
bool Dispatch();
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD Run() override;
|
2014-02-25 01:09:03 +04:00
|
|
|
void Destroy();
|
|
|
|
};
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
RefPtr<IORunnable> mRunnable;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<FilePickerShownCallback> mCallback;
|
2014-02-18 04:30:06 +04:00
|
|
|
nsCOMPtr<nsIFilePicker> mFilePicker;
|
|
|
|
|
|
|
|
nsString mTitle;
|
|
|
|
int16_t mMode;
|
2014-02-25 01:09:03 +04:00
|
|
|
int16_t mResult;
|
2014-02-18 04:30:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-01-05 12:59:30 +03:00
|
|
|
#endif // mozilla_dom_FilePickerParent_h
|