1999-11-16 01:51:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
1999-11-16 01:51:39 +00:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2005-11-28 23:56:44 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
2004-10-15 17:19:20 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
1999-11-16 01:51:39 +00:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
2000-08-25 02:17:53 +00:00
|
|
|
#include "nsIStringBundle.h"
|
2017-08-17 05:29:03 +00:00
|
|
|
#include "nsString.h"
|
2009-03-30 18:08:06 +00:00
|
|
|
#include "nsCOMArray.h"
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2002-09-07 05:23:45 +00:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2016-03-20 10:56:10 +00:00
|
|
|
#include "mozilla/dom/Directory.h"
|
2014-10-08 16:15:23 +00:00
|
|
|
#include "mozilla/dom/File.h"
|
2010-05-14 09:24:41 +00:00
|
|
|
#include "mozilla/Services.h"
|
2010-06-25 21:51:17 +00:00
|
|
|
#include "WidgetUtils.h"
|
2018-08-18 21:22:47 +00:00
|
|
|
#include "nsSimpleEnumerator.h"
|
2012-08-17 15:35:01 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2000-08-25 02:17:53 +00:00
|
|
|
|
1999-11-16 01:51:39 +00:00
|
|
|
#include "nsBaseFilePicker.h"
|
|
|
|
|
2010-06-25 21:51:17 +00:00
|
|
|
using namespace mozilla::widget;
|
2014-06-26 16:47:44 +00:00
|
|
|
using namespace mozilla::dom;
|
2010-06-25 21:51:17 +00:00
|
|
|
|
2010-02-20 15:26:41 +00:00
|
|
|
#define FILEPICKER_TITLES "chrome://global/locale/filepicker.properties"
|
|
|
|
#define FILEPICKER_FILTERS "chrome://global/content/filepicker.properties"
|
2000-08-25 02:17:53 +00:00
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
nsresult LocalFileToDirectoryOrBlob(nsPIDOMWindowInner* aWindow,
|
|
|
|
bool aIsDirectory, nsIFile* aFile,
|
|
|
|
nsISupports** aResult) {
|
2019-10-21 05:33:33 +00:00
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
if (aIsDirectory) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool isDir;
|
|
|
|
aFile->IsDirectory(&isDir);
|
|
|
|
MOZ_ASSERT(isDir);
|
|
|
|
#endif
|
|
|
|
|
2019-10-21 05:33:33 +00:00
|
|
|
RefPtr<Directory> directory = Directory::Create(aWindow->AsGlobal(), aFile);
|
2016-03-20 10:56:10 +00:00
|
|
|
MOZ_ASSERT(directory);
|
|
|
|
|
|
|
|
directory.forget(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-10-21 05:33:33 +00:00
|
|
|
RefPtr<File> file = File::CreateFromFile(aWindow->AsGlobal(), aFile);
|
2019-10-21 05:33:19 +00:00
|
|
|
if (NS_WARN_IF(!file)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-05-22 00:23:10 +00:00
|
|
|
file.forget(aResult);
|
2016-03-20 10:56:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2012-08-17 15:35:01 +00:00
|
|
|
/**
|
|
|
|
* A runnable to dispatch from the main thread to the main thread to display
|
|
|
|
* the file picker while letting the showAsync method return right away.
|
|
|
|
*/
|
2017-08-06 04:15:31 +00:00
|
|
|
class nsBaseFilePicker::AsyncShowFilePicker : public mozilla::Runnable {
|
2012-08-17 15:35:01 +00:00
|
|
|
public:
|
2017-08-06 04:15:31 +00:00
|
|
|
AsyncShowFilePicker(nsBaseFilePicker* aFilePicker,
|
2017-06-12 19:34:10 +00:00
|
|
|
nsIFilePickerShownCallback* aCallback)
|
|
|
|
: mozilla::Runnable("AsyncShowFilePicker"),
|
|
|
|
mFilePicker(aFilePicker),
|
|
|
|
mCallback(aCallback) {}
|
2012-08-17 15:35:01 +00:00
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override {
|
2012-08-17 15:35:01 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(),
|
|
|
|
"AsyncShowFilePicker should be on the main thread!");
|
|
|
|
|
|
|
|
// It's possible that some widget implementations require GUI operations
|
|
|
|
// to be on the main thread, so that's why we're not dispatching to another
|
|
|
|
// thread and calling back to the main after it's done.
|
2012-08-29 18:37:43 +00:00
|
|
|
int16_t result = nsIFilePicker::returnCancel;
|
2012-08-17 15:35:01 +00:00
|
|
|
nsresult rv = mFilePicker->Show(&result);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("FilePicker's Show() implementation failed!");
|
|
|
|
}
|
|
|
|
|
2012-08-29 18:37:43 +00:00
|
|
|
if (mCallback) {
|
|
|
|
mCallback->Done(result);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2012-08-17 15:35:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-08-06 04:15:31 +00:00
|
|
|
RefPtr<nsBaseFilePicker> mFilePicker;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsIFilePickerShownCallback> mCallback;
|
2012-08-17 15:35:01 +00:00
|
|
|
};
|
|
|
|
|
2018-08-18 21:22:47 +00:00
|
|
|
class nsBaseFilePickerEnumerator : public nsSimpleEnumerator {
|
2013-03-19 17:49:16 +00:00
|
|
|
public:
|
2016-03-20 10:56:10 +00:00
|
|
|
nsBaseFilePickerEnumerator(nsPIDOMWindowOuter* aParent,
|
|
|
|
nsISimpleEnumerator* iterator, int16_t aMode)
|
2013-03-19 17:49:16 +00:00
|
|
|
: mIterator(iterator),
|
2016-01-30 17:05:36 +00:00
|
|
|
mParent(aParent->GetCurrentInnerWindow()),
|
2015-07-10 17:55:52 +00:00
|
|
|
mMode(aMode) {}
|
2013-03-19 17:49:16 +00:00
|
|
|
|
2018-08-19 04:06:32 +00:00
|
|
|
const nsID& DefaultInterface() override { return NS_GET_IID(nsIFile); }
|
|
|
|
|
2013-03-19 17:49:16 +00:00
|
|
|
NS_IMETHOD
|
2015-03-21 16:28:04 +00:00
|
|
|
GetNext(nsISupports** aResult) override {
|
2013-03-19 17:49:16 +00:00
|
|
|
nsCOMPtr<nsISupports> tmp;
|
|
|
|
nsresult rv = mIterator->GetNext(getter_AddRefs(tmp));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!tmp) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> localFile = do_QueryInterface(tmp);
|
|
|
|
if (!localFile) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-10-21 05:33:33 +00:00
|
|
|
if (!mParent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
return LocalFileToDirectoryOrBlob(
|
|
|
|
mParent, mMode == nsIFilePicker::modeGetFolder, localFile, aResult);
|
2013-03-19 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2015-03-21 16:28:04 +00:00
|
|
|
HasMoreElements(bool* aResult) override {
|
2013-03-19 17:49:16 +00:00
|
|
|
return mIterator->HasMoreElements(aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> mIterator;
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mParent;
|
2015-07-10 17:55:52 +00:00
|
|
|
int16_t mMode;
|
2013-03-19 17:49:16 +00:00
|
|
|
};
|
|
|
|
|
2013-07-22 09:12:32 +00:00
|
|
|
nsBaseFilePicker::nsBaseFilePicker()
|
|
|
|
: mAddToRecentDocs(true), mMode(nsIFilePicker::modeOpen) {}
|
1999-11-16 01:51:39 +00:00
|
|
|
|
|
|
|
nsBaseFilePicker::~nsBaseFilePicker() {}
|
|
|
|
|
2016-01-30 17:05:36 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::Init(mozIDOMWindowProxy* aParent,
|
2004-04-21 23:38:22 +00:00
|
|
|
const nsAString& aTitle, int16_t aMode) {
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aParent,
|
|
|
|
"Null parent passed to filepicker, no file "
|
2004-04-21 23:38:22 +00:00
|
|
|
"picker for you!");
|
2016-01-30 17:05:36 +00:00
|
|
|
|
|
|
|
mParent = nsPIDOMWindowOuter::From(aParent);
|
|
|
|
|
2019-04-11 14:14:15 +00:00
|
|
|
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(mParent);
|
2004-04-21 23:38:22 +00:00
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
1999-11-16 01:51:39 +00:00
|
|
|
|
2013-07-22 09:12:32 +00:00
|
|
|
mMode = aMode;
|
|
|
|
InitNative(widget, aTitle);
|
1999-11-16 01:51:39 +00:00
|
|
|
|
2004-04-21 23:38:22 +00:00
|
|
|
return NS_OK;
|
1999-11-16 01:51:39 +00:00
|
|
|
}
|
2000-08-25 02:17:53 +00:00
|
|
|
|
2012-08-17 15:35:01 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseFilePicker::Open(nsIFilePickerShownCallback* aCallback) {
|
|
|
|
nsCOMPtr<nsIRunnable> filePickerEvent =
|
|
|
|
new AsyncShowFilePicker(this, aCallback);
|
|
|
|
return NS_DispatchToMainThread(filePickerEvent);
|
|
|
|
}
|
2000-08-25 02:17:53 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBaseFilePicker::AppendFilters(int32_t aFilterMask) {
|
2010-05-14 09:24:41 +00:00
|
|
|
nsCOMPtr<nsIStringBundleService> stringService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
|
|
|
if (!stringService) return NS_ERROR_FAILURE;
|
2009-03-29 19:51:41 +00:00
|
|
|
|
2010-02-20 15:26:41 +00:00
|
|
|
nsCOMPtr<nsIStringBundle> titleBundle, filterBundle;
|
2000-08-25 02:17:53 +00:00
|
|
|
|
2010-05-14 09:24:41 +00:00
|
|
|
nsresult rv = stringService->CreateBundle(FILEPICKER_TITLES,
|
|
|
|
getter_AddRefs(titleBundle));
|
2010-02-20 15:26:41 +00:00
|
|
|
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = stringService->CreateBundle(FILEPICKER_FILTERS,
|
|
|
|
getter_AddRefs(filterBundle));
|
2000-08-25 02:17:53 +00:00
|
|
|
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
|
|
|
|
2017-08-04 04:40:52 +00:00
|
|
|
nsAutoString title;
|
|
|
|
nsAutoString filter;
|
2000-08-25 02:17:53 +00:00
|
|
|
|
|
|
|
if (aFilterMask & filterAll) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("allTitle", title);
|
|
|
|
filterBundle->GetStringFromName("allFilter", filter);
|
2000-08-25 02:17:53 +00:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterHTML) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("htmlTitle", title);
|
|
|
|
filterBundle->GetStringFromName("htmlFilter", filter);
|
2000-08-25 02:17:53 +00:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterText) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("textTitle", title);
|
|
|
|
filterBundle->GetStringFromName("textFilter", filter);
|
2000-08-25 02:17:53 +00:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterImages) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("imageTitle", title);
|
|
|
|
filterBundle->GetStringFromName("imageFilter", filter);
|
2010-02-20 15:26:41 +00:00
|
|
|
AppendFilter(title, filter);
|
2000-08-25 02:17:53 +00:00
|
|
|
}
|
2010-07-17 07:00:28 +00:00
|
|
|
if (aFilterMask & filterAudio) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("audioTitle", title);
|
|
|
|
filterBundle->GetStringFromName("audioFilter", filter);
|
2010-07-17 07:00:28 +00:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterVideo) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("videoTitle", title);
|
|
|
|
filterBundle->GetStringFromName("videoFilter", filter);
|
2010-07-17 07:00:28 +00:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
2000-08-25 02:17:53 +00:00
|
|
|
if (aFilterMask & filterXML) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("xmlTitle", title);
|
|
|
|
filterBundle->GetStringFromName("xmlFilter", filter);
|
2000-08-25 02:17:53 +00:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterXUL) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("xulTitle", title);
|
|
|
|
filterBundle->GetStringFromName("xulFilter", filter);
|
2000-08-25 02:17:53 +00:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
2002-07-07 07:21:45 +00:00
|
|
|
if (aFilterMask & filterApps) {
|
2017-08-04 04:40:52 +00:00
|
|
|
titleBundle->GetStringFromName("appsTitle", title);
|
2002-07-07 07:21:45 +00:00
|
|
|
// Pass the magic string "..apps" to the platform filepicker, which it
|
|
|
|
// should recognize and do the correct platform behavior for.
|
2004-04-21 23:38:22 +00:00
|
|
|
AppendFilter(title, NS_LITERAL_STRING("..apps"));
|
2002-07-07 07:21:45 +00:00
|
|
|
}
|
2000-08-25 02:17:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-24 16:21:05 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::AppendRawFilter(const nsAString& aFilter) {
|
|
|
|
mRawFilters.AppendElement(aFilter);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-07-30 18:13:05 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetCapture(int16_t* aCapture) {
|
|
|
|
*aCapture = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseFilePicker::SetCapture(int16_t aCapture) { return NS_OK; }
|
|
|
|
|
2001-12-12 04:17:26 +00:00
|
|
|
// Set the filter index
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetFilterIndex(int32_t* aFilterIndex) {
|
2001-12-12 04:17:26 +00:00
|
|
|
*aFilterIndex = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::SetFilterIndex(int32_t aFilterIndex) {
|
2001-12-12 04:17:26 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-25 02:17:53 +00:00
|
|
|
|
2002-09-07 05:23:45 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetFiles(nsISimpleEnumerator** aFiles) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aFiles);
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMArray<nsIFile> files;
|
2009-03-30 18:08:06 +00:00
|
|
|
nsresult rv;
|
2002-09-07 05:23:45 +00:00
|
|
|
|
|
|
|
// if we get into the base class, the platform
|
|
|
|
// doesn't implement GetFiles() yet.
|
|
|
|
// so we fake it.
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2002-09-07 05:23:45 +00:00
|
|
|
rv = GetFile(getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-07-27 13:52:43 +00:00
|
|
|
files.AppendObject(file);
|
2002-09-07 05:23:45 +00:00
|
|
|
|
2018-08-19 04:06:32 +00:00
|
|
|
return NS_NewArrayEnumerator(aFiles, files, NS_GET_IID(nsIFile));
|
2002-09-07 05:23:45 +00:00
|
|
|
}
|
2005-01-14 11:41:37 +00:00
|
|
|
|
|
|
|
// Set the display directory
|
2012-06-06 02:08:30 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::SetDisplayDirectory(nsIFile* aDirectory) {
|
2017-04-26 16:20:19 +00:00
|
|
|
// if displaySpecialDirectory has been previously called, let's abort this
|
|
|
|
// operation.
|
|
|
|
if (!mDisplaySpecialDirectory.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-25 11:57:29 +00:00
|
|
|
if (!aDirectory) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mDisplayDirectory = nullptr;
|
2005-01-14 12:02:50 +00:00
|
|
|
return NS_OK;
|
2005-01-25 11:57:29 +00:00
|
|
|
}
|
2005-01-14 11:41:37 +00:00
|
|
|
nsCOMPtr<nsIFile> directory;
|
|
|
|
nsresult rv = aDirectory->Clone(getter_AddRefs(directory));
|
2005-01-25 11:57:29 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-10-01 21:38:43 +00:00
|
|
|
mDisplayDirectory = directory;
|
|
|
|
return NS_OK;
|
2005-01-14 11:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the display directory
|
2012-06-06 02:08:30 +00:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetDisplayDirectory(nsIFile** aDirectory) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aDirectory = nullptr;
|
2017-04-26 16:20:19 +00:00
|
|
|
|
|
|
|
// if displaySpecialDirectory has been previously called, let's abort this
|
|
|
|
// operation.
|
|
|
|
if (!mDisplaySpecialDirectory.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-25 11:57:29 +00:00
|
|
|
if (!mDisplayDirectory) return NS_OK;
|
2005-01-14 11:41:37 +00:00
|
|
|
nsCOMPtr<nsIFile> directory;
|
|
|
|
nsresult rv = mDisplayDirectory->Clone(getter_AddRefs(directory));
|
2014-03-17 17:00:17 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2005-01-14 11:41:37 +00:00
|
|
|
return rv;
|
2014-03-17 17:00:17 +00:00
|
|
|
}
|
|
|
|
directory.forget(aDirectory);
|
|
|
|
return NS_OK;
|
2005-01-14 11:41:37 +00:00
|
|
|
}
|
2011-05-24 12:28:19 +00:00
|
|
|
|
2017-04-26 16:20:19 +00:00
|
|
|
// Set the display special directory
|
|
|
|
NS_IMETHODIMP nsBaseFilePicker::SetDisplaySpecialDirectory(
|
|
|
|
const nsAString& aDirectory) {
|
|
|
|
// if displayDirectory has been previously called, let's abort this operation.
|
|
|
|
if (mDisplayDirectory && mDisplaySpecialDirectory.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mDisplaySpecialDirectory = aDirectory;
|
|
|
|
if (mDisplaySpecialDirectory.IsEmpty()) {
|
|
|
|
mDisplayDirectory = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_GetSpecialDirectory(
|
|
|
|
NS_ConvertUTF16toUTF8(mDisplaySpecialDirectory).get(),
|
|
|
|
getter_AddRefs(mDisplayDirectory));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the display special directory
|
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetDisplaySpecialDirectory(
|
|
|
|
nsAString& aDirectory) {
|
|
|
|
aDirectory = mDisplaySpecialDirectory;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-24 12:28:19 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBaseFilePicker::GetAddToRecentDocs(bool* aFlag) {
|
2011-05-24 12:28:19 +00:00
|
|
|
*aFlag = mAddToRecentDocs;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBaseFilePicker::SetAddToRecentDocs(bool aFlag) {
|
2011-05-24 12:28:19 +00:00
|
|
|
mAddToRecentDocs = aFlag;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-19 17:49:16 +00:00
|
|
|
|
2013-07-22 12:46:27 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseFilePicker::GetMode(int16_t* aMode) {
|
|
|
|
*aMode = mMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:07:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseFilePicker::SetOkButtonLabel(const nsAString& aLabel) {
|
|
|
|
mOkButtonLabel = aLabel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseFilePicker::GetOkButtonLabel(nsAString& aLabel) {
|
|
|
|
aLabel = mOkButtonLabel;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-19 17:49:16 +00:00
|
|
|
NS_IMETHODIMP
|
2016-01-12 19:18:15 +00:00
|
|
|
nsBaseFilePicker::GetDomFileOrDirectory(nsISupports** aValue) {
|
2013-03-19 17:49:16 +00:00
|
|
|
nsCOMPtr<nsIFile> localFile;
|
|
|
|
nsresult rv = GetFile(getter_AddRefs(localFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!localFile) {
|
2016-01-12 19:18:15 +00:00
|
|
|
*aValue = nullptr;
|
2013-03-19 17:49:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-05 18:12:25 +00:00
|
|
|
auto* innerParent = mParent ? mParent->GetCurrentInnerWindow() : nullptr;
|
|
|
|
|
2019-10-21 05:33:33 +00:00
|
|
|
if (!innerParent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
return LocalFileToDirectoryOrBlob(
|
|
|
|
innerParent, mMode == nsIFilePicker::modeGetFolder, localFile, aValue);
|
2013-03-19 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-12 19:18:15 +00:00
|
|
|
nsBaseFilePicker::GetDomFileOrDirectoryEnumerator(
|
|
|
|
nsISimpleEnumerator** aValue) {
|
2013-03-19 17:49:16 +00:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> iter;
|
|
|
|
nsresult rv = GetFiles(getter_AddRefs(iter));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsBaseFilePickerEnumerator> retIter =
|
2015-07-10 17:55:52 +00:00
|
|
|
new nsBaseFilePickerEnumerator(mParent, iter, mMode);
|
2013-03-19 17:49:16 +00:00
|
|
|
|
2016-01-12 19:18:15 +00:00
|
|
|
retIter.forget(aValue);
|
2013-03-19 17:49:16 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|