1999-11-16 04:51:39 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04: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 04:51:39 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2005-11-29 02:56:44 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
2000-02-08 17:22:19 +03:00
|
|
|
#include "nsIDocShell.h"
|
2004-10-15 21:19:20 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2004-08-20 19:08:28 +04:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-11-16 04:51:39 +03:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
2000-08-25 06:17:53 +04:00
|
|
|
#include "nsIStringBundle.h"
|
2000-08-30 08:20:08 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2009-03-30 22:08:06 +04:00
|
|
|
#include "nsCOMArray.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2002-09-07 09:23:45 +04:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2016-03-20 13:56:10 +03:00
|
|
|
#include "mozilla/dom/Directory.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2010-05-14 13:24:41 +04:00
|
|
|
#include "mozilla/Services.h"
|
2010-06-26 01:51:17 +04:00
|
|
|
#include "WidgetUtils.h"
|
2012-08-17 19:35:01 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2000-08-25 06:17:53 +04:00
|
|
|
|
1999-11-16 04:51:39 +03:00
|
|
|
#include "nsBaseFilePicker.h"
|
|
|
|
|
2010-06-26 01:51:17 +04:00
|
|
|
using namespace mozilla::widget;
|
2014-06-26 20:47:44 +04:00
|
|
|
using namespace mozilla::dom;
|
2010-06-26 01:51:17 +04:00
|
|
|
|
2010-02-20 18:26:41 +03:00
|
|
|
#define FILEPICKER_TITLES "chrome://global/locale/filepicker.properties"
|
|
|
|
#define FILEPICKER_FILTERS "chrome://global/content/filepicker.properties"
|
2000-08-25 06:17:53 +04:00
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
LocalFileToDirectoryOrBlob(nsPIDOMWindowInner* aWindow,
|
|
|
|
bool aIsDirectory,
|
|
|
|
nsIFile* aFile,
|
|
|
|
nsISupports** aResult)
|
|
|
|
{
|
|
|
|
if (aIsDirectory) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool isDir;
|
|
|
|
aFile->IsDirectory(&isDir);
|
|
|
|
MOZ_ASSERT(isDir);
|
|
|
|
#endif
|
|
|
|
|
2016-04-18 10:32:30 +03:00
|
|
|
RefPtr<Directory> directory = Directory::Create(aWindow, aFile);
|
2016-03-20 13:56:10 +03:00
|
|
|
MOZ_ASSERT(directory);
|
|
|
|
|
|
|
|
directory.forget(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMBlob> blob = File::CreateFromFile(aWindow, aFile);
|
|
|
|
blob.forget(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2012-08-17 19:35:01 +04: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.
|
|
|
|
*/
|
2016-04-26 03:23:21 +03:00
|
|
|
class AsyncShowFilePicker : public mozilla::Runnable
|
2012-08-17 19:35:01 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-21 14:59:26 +03:00
|
|
|
AsyncShowFilePicker(nsIFilePicker *aFilePicker,
|
|
|
|
nsIFilePickerShownCallback *aCallback) :
|
|
|
|
mFilePicker(aFilePicker),
|
|
|
|
mCallback(aCallback)
|
2012-08-17 19:35:01 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2012-08-17 19:35:01 +04: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 22:37:43 +04:00
|
|
|
int16_t result = nsIFilePicker::returnCancel;
|
2012-08-17 19:35:01 +04:00
|
|
|
nsresult rv = mFilePicker->Show(&result);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ERROR("FilePicker's Show() implementation failed!");
|
|
|
|
}
|
|
|
|
|
2012-08-29 22:37:43 +04:00
|
|
|
if (mCallback) {
|
|
|
|
mCallback->Done(result);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2012-08-17 19:35:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsIFilePicker> mFilePicker;
|
|
|
|
RefPtr<nsIFilePickerShownCallback> mCallback;
|
2012-08-17 19:35:01 +04:00
|
|
|
};
|
|
|
|
|
2013-03-19 21:49:16 +04:00
|
|
|
class nsBaseFilePickerEnumerator : public nsISimpleEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
nsBaseFilePickerEnumerator(nsPIDOMWindowOuter* aParent,
|
|
|
|
nsISimpleEnumerator* iterator,
|
|
|
|
int16_t aMode)
|
2013-03-19 21:49:16 +04:00
|
|
|
: mIterator(iterator)
|
2016-01-30 20:05:36 +03:00
|
|
|
, mParent(aParent->GetCurrentInnerWindow())
|
2015-07-10 20:55:52 +03:00
|
|
|
, mMode(aMode)
|
2013-03-19 21:49:16 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2015-03-21 19:28:04 +03:00
|
|
|
GetNext(nsISupports** aResult) override
|
2013-03-19 21:49:16 +04: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;
|
|
|
|
}
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
return LocalFileToDirectoryOrBlob(mParent,
|
|
|
|
mMode == nsIFilePicker::modeGetFolder,
|
|
|
|
localFile,
|
|
|
|
aResult);
|
2013-03-19 21:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
2015-03-21 19:28:04 +03:00
|
|
|
HasMoreElements(bool* aResult) override
|
2013-03-19 21:49:16 +04:00
|
|
|
{
|
|
|
|
return mIterator->HasMoreElements(aResult);
|
|
|
|
}
|
|
|
|
|
2014-06-24 20:36:44 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsBaseFilePickerEnumerator()
|
|
|
|
{}
|
|
|
|
|
2013-03-19 21:49:16 +04:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> mIterator;
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mParent;
|
2015-07-10 20:55:52 +03:00
|
|
|
int16_t mMode;
|
2013-03-19 21:49:16 +04:00
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsBaseFilePickerEnumerator, nsISimpleEnumerator)
|
2013-03-19 21:49:16 +04:00
|
|
|
|
2013-07-22 13:12:32 +04:00
|
|
|
nsBaseFilePicker::nsBaseFilePicker()
|
|
|
|
: mAddToRecentDocs(true)
|
|
|
|
, mMode(nsIFilePicker::modeOpen)
|
1999-11-16 04:51:39 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBaseFilePicker::~nsBaseFilePicker()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::Init(mozIDOMWindowProxy* aParent,
|
2004-04-22 03:38:22 +04:00
|
|
|
const nsAString& aTitle,
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t aMode)
|
1999-11-16 04:51:39 +03:00
|
|
|
{
|
2004-04-22 03:38:22 +04:00
|
|
|
NS_PRECONDITION(aParent, "Null parent passed to filepicker, no file "
|
|
|
|
"picker for you!");
|
2016-01-30 20:05:36 +03:00
|
|
|
|
|
|
|
mParent = nsPIDOMWindowOuter::From(aParent);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(mParent->GetOuterWindow());
|
2004-04-22 03:38:22 +04:00
|
|
|
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
1999-11-16 04:51:39 +03:00
|
|
|
|
2014-10-10 20:00:34 +04:00
|
|
|
|
2013-07-22 13:12:32 +04:00
|
|
|
mMode = aMode;
|
|
|
|
InitNative(widget, aTitle);
|
1999-11-16 04:51:39 +03:00
|
|
|
|
2004-04-22 03:38:22 +04:00
|
|
|
return NS_OK;
|
1999-11-16 04:51:39 +03:00
|
|
|
}
|
2000-08-25 06:17:53 +04:00
|
|
|
|
2012-08-17 19:35:01 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseFilePicker::Open(nsIFilePickerShownCallback *aCallback)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> filePickerEvent =
|
|
|
|
new AsyncShowFilePicker(this, aCallback);
|
|
|
|
return NS_DispatchToMainThread(filePickerEvent);
|
|
|
|
}
|
2000-08-25 06:17:53 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsBaseFilePicker::AppendFilters(int32_t aFilterMask)
|
2000-08-25 06:17:53 +04:00
|
|
|
{
|
2010-05-14 13:24:41 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> stringService =
|
|
|
|
mozilla::services::GetStringBundleService();
|
|
|
|
if (!stringService)
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-03-29 23:51:41 +04:00
|
|
|
|
2010-02-20 18:26:41 +03:00
|
|
|
nsCOMPtr<nsIStringBundle> titleBundle, filterBundle;
|
2000-08-25 06:17:53 +04:00
|
|
|
|
2010-05-14 13:24:41 +04:00
|
|
|
nsresult rv = stringService->CreateBundle(FILEPICKER_TITLES,
|
|
|
|
getter_AddRefs(titleBundle));
|
2010-02-20 18:26:41 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
rv = stringService->CreateBundle(FILEPICKER_FILTERS, getter_AddRefs(filterBundle));
|
2000-08-25 06:17:53 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-08-30 08:20:08 +04:00
|
|
|
nsXPIDLString title;
|
|
|
|
nsXPIDLString filter;
|
2000-08-25 06:17:53 +04:00
|
|
|
|
|
|
|
if (aFilterMask & filterAll) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"allTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"allFilter", getter_Copies(filter));
|
2000-08-25 06:17:53 +04:00
|
|
|
AppendFilter(title,filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterHTML) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"htmlTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"htmlFilter", getter_Copies(filter));
|
2000-08-25 06:17:53 +04:00
|
|
|
AppendFilter(title,filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterText) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"textTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"textFilter", getter_Copies(filter));
|
2000-08-25 06:17:53 +04:00
|
|
|
AppendFilter(title,filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterImages) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"imageTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"imageFilter", getter_Copies(filter));
|
2010-02-20 18:26:41 +03:00
|
|
|
AppendFilter(title,filter);
|
2000-08-25 06:17:53 +04:00
|
|
|
}
|
2010-07-17 11:00:28 +04:00
|
|
|
if (aFilterMask & filterAudio) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"audioTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"audioFilter", getter_Copies(filter));
|
2010-07-17 11:00:28 +04:00
|
|
|
AppendFilter(title,filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterVideo) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"videoTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"videoFilter", getter_Copies(filter));
|
2010-07-17 11:00:28 +04:00
|
|
|
AppendFilter(title,filter);
|
|
|
|
}
|
2000-08-25 06:17:53 +04:00
|
|
|
if (aFilterMask & filterXML) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"xmlTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"xmlFilter", getter_Copies(filter));
|
2000-08-25 06:17:53 +04:00
|
|
|
AppendFilter(title,filter);
|
|
|
|
}
|
|
|
|
if (aFilterMask & filterXUL) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"xulTitle", getter_Copies(title));
|
|
|
|
filterBundle->GetStringFromName(u"xulFilter", getter_Copies(filter));
|
2000-08-25 06:17:53 +04:00
|
|
|
AppendFilter(title, filter);
|
|
|
|
}
|
2002-07-07 11:21:45 +04:00
|
|
|
if (aFilterMask & filterApps) {
|
2016-07-21 08:03:25 +03:00
|
|
|
titleBundle->GetStringFromName(u"appsTitle", getter_Copies(title));
|
2002-07-07 11:21:45 +04:00
|
|
|
// Pass the magic string "..apps" to the platform filepicker, which it
|
|
|
|
// should recognize and do the correct platform behavior for.
|
2004-04-22 03:38:22 +04:00
|
|
|
AppendFilter(title, NS_LITERAL_STRING("..apps"));
|
2002-07-07 11:21:45 +04:00
|
|
|
}
|
2000-08-25 06:17:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-12 07:17:26 +03:00
|
|
|
// Set the filter index
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetFilterIndex(int32_t *aFilterIndex)
|
2001-12-12 07:17:26 +03:00
|
|
|
{
|
|
|
|
*aFilterIndex = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::SetFilterIndex(int32_t aFilterIndex)
|
2001-12-12 07:17:26 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-25 06:17:53 +04:00
|
|
|
|
2002-09-07 09:23:45 +04:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetFiles(nsISimpleEnumerator **aFiles)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aFiles);
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMArray <nsIFile> files;
|
2009-03-30 22:08:06 +04:00
|
|
|
nsresult rv;
|
2002-09-07 09:23:45 +04:00
|
|
|
|
|
|
|
// if we get into the base class, the platform
|
|
|
|
// doesn't implement GetFiles() yet.
|
|
|
|
// so we fake it.
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr <nsIFile> file;
|
2002-09-07 09:23:45 +04:00
|
|
|
rv = GetFile(getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
2012-07-27 17:52:43 +04:00
|
|
|
files.AppendObject(file);
|
2002-09-07 09:23:45 +04:00
|
|
|
|
|
|
|
return NS_NewArrayEnumerator(aFiles, files);
|
|
|
|
}
|
2005-01-14 14:41:37 +03:00
|
|
|
|
|
|
|
// Set the display directory
|
2012-06-06 06:08:30 +04:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::SetDisplayDirectory(nsIFile *aDirectory)
|
2005-01-14 14:41:37 +03:00
|
|
|
{
|
2017-04-26 19:20:19 +03:00
|
|
|
// if displaySpecialDirectory has been previously called, let's abort this
|
|
|
|
// operation.
|
|
|
|
if (!mDisplaySpecialDirectory.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-25 14:57:29 +03:00
|
|
|
if (!aDirectory) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mDisplayDirectory = nullptr;
|
2005-01-14 15:02:50 +03:00
|
|
|
return NS_OK;
|
2005-01-25 14:57:29 +03:00
|
|
|
}
|
2005-01-14 14:41:37 +03:00
|
|
|
nsCOMPtr<nsIFile> directory;
|
|
|
|
nsresult rv = aDirectory->Clone(getter_AddRefs(directory));
|
2005-01-25 14:57:29 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2005-01-14 14:41:37 +03:00
|
|
|
mDisplayDirectory = do_QueryInterface(directory, &rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the display directory
|
2012-06-06 06:08:30 +04:00
|
|
|
NS_IMETHODIMP nsBaseFilePicker::GetDisplayDirectory(nsIFile **aDirectory)
|
2005-01-14 14:41:37 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDirectory = nullptr;
|
2017-04-26 19:20:19 +03:00
|
|
|
|
|
|
|
// if displaySpecialDirectory has been previously called, let's abort this
|
|
|
|
// operation.
|
|
|
|
if (!mDisplaySpecialDirectory.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-25 14:57:29 +03:00
|
|
|
if (!mDisplayDirectory)
|
2005-01-14 14:41:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
nsCOMPtr<nsIFile> directory;
|
|
|
|
nsresult rv = mDisplayDirectory->Clone(getter_AddRefs(directory));
|
2014-03-17 21:00:17 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2005-01-14 14:41:37 +03:00
|
|
|
return rv;
|
2014-03-17 21:00:17 +04:00
|
|
|
}
|
|
|
|
directory.forget(aDirectory);
|
|
|
|
return NS_OK;
|
2005-01-14 14:41:37 +03:00
|
|
|
}
|
2011-05-24 16:28:19 +04:00
|
|
|
|
2017-04-26 19:20:19 +03: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 16:28:19 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseFilePicker::GetAddToRecentDocs(bool *aFlag)
|
2011-05-24 16:28:19 +04:00
|
|
|
{
|
|
|
|
*aFlag = mAddToRecentDocs;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsBaseFilePicker::SetAddToRecentDocs(bool aFlag)
|
2011-05-24 16:28:19 +04:00
|
|
|
{
|
|
|
|
mAddToRecentDocs = aFlag;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-19 21:49:16 +04:00
|
|
|
|
2013-07-22 16:46:27 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseFilePicker::GetMode(int16_t* aMode)
|
|
|
|
{
|
|
|
|
*aMode = mMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-24 02:07:21 +03: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 21:49:16 +04:00
|
|
|
NS_IMETHODIMP
|
2016-01-12 22:18:15 +03:00
|
|
|
nsBaseFilePicker::GetDomFileOrDirectory(nsISupports** aValue)
|
2013-03-19 21:49:16 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> localFile;
|
|
|
|
nsresult rv = GetFile(getter_AddRefs(localFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!localFile) {
|
2016-01-12 22:18:15 +03:00
|
|
|
*aValue = nullptr;
|
2013-03-19 21:49:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-05 21:12:25 +03:00
|
|
|
auto* innerParent = mParent ? mParent->GetCurrentInnerWindow() : nullptr;
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
return LocalFileToDirectoryOrBlob(innerParent,
|
|
|
|
mMode == nsIFilePicker::modeGetFolder,
|
|
|
|
localFile,
|
|
|
|
aValue);
|
2013-03-19 21:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-01-12 22:18:15 +03:00
|
|
|
nsBaseFilePicker::GetDomFileOrDirectoryEnumerator(nsISimpleEnumerator** aValue)
|
2013-03-19 21:49:16 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> iter;
|
|
|
|
nsresult rv = GetFiles(getter_AddRefs(iter));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsBaseFilePickerEnumerator> retIter =
|
2015-07-10 20:55:52 +03:00
|
|
|
new nsBaseFilePickerEnumerator(mParent, iter, mMode);
|
2013-03-19 21:49:16 +04:00
|
|
|
|
2016-01-12 22:18:15 +03:00
|
|
|
retIter.forget(aValue);
|
2013-03-19 21:49:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|