2014-03-05 07:26:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-05 07:26:39 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Directory_h
|
|
|
|
#define mozilla_dom_Directory_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-07-19 05:31:11 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-03-05 07:26:39 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-03-05 07:26:39 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
class FileSystemBase;
|
2014-03-05 07:26:39 +04:00
|
|
|
class Promise;
|
2014-03-12 10:30:21 +04:00
|
|
|
class StringOrFileOrDirectory;
|
2014-03-05 07:26:39 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class Directory final
|
2014-03-05 07:26:39 +04:00
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory)
|
|
|
|
|
2016-05-13 14:11:38 +03:00
|
|
|
static bool
|
|
|
|
WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2016-06-01 13:29:00 +03:00
|
|
|
static already_AddRefed<Directory>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aRealPath,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
static already_AddRefed<Directory>
|
2016-03-20 13:56:10 +03:00
|
|
|
Create(nsISupports* aParent, nsIFile* aDirectory,
|
2016-04-18 10:32:30 +03:00
|
|
|
FileSystemBase* aFileSystem = 0);
|
2014-03-05 07:26:39 +04:00
|
|
|
|
|
|
|
// ========= Begin WebIDL bindings. ===========
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
nsISupports*
|
2014-03-05 07:26:39 +04:00
|
|
|
GetParentObject() const;
|
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-03-05 07:26:39 +04:00
|
|
|
|
|
|
|
void
|
2016-03-20 13:56:10 +03:00
|
|
|
GetName(nsAString& aRetval, ErrorResult& aRv);
|
2014-03-05 07:26:39 +04:00
|
|
|
|
2015-06-23 02:31:34 +03:00
|
|
|
// From https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface :
|
|
|
|
|
|
|
|
void
|
2016-03-20 13:56:10 +03:00
|
|
|
GetPath(nsAString& aRetval, ErrorResult& aRv);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetFullRealPath(nsAString& aPath);
|
2015-06-23 02:31:34 +03:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2016-03-20 13:56:10 +03:00
|
|
|
GetFilesAndDirectories(ErrorResult& aRv);
|
2015-06-23 02:31:34 +03:00
|
|
|
|
2016-04-13 14:15:56 +03:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
GetFiles(bool aRecursiveFlag, ErrorResult& aRv);
|
|
|
|
|
2014-03-05 07:26:39 +04:00
|
|
|
// =========== End WebIDL bindings.============
|
2014-03-12 10:30:21 +04:00
|
|
|
|
2015-10-09 17:59:40 +03:00
|
|
|
/**
|
|
|
|
* Sets a semi-colon separated list of filters to filter-in or filter-out
|
|
|
|
* certain types of files when the contents of this directory are requested
|
|
|
|
* via a GetFilesAndDirectories() call.
|
|
|
|
*
|
|
|
|
* Currently supported keywords:
|
|
|
|
*
|
|
|
|
* * filter-out-sensitive
|
|
|
|
* This keyword filters out files or directories that we don't wish to
|
|
|
|
* make available to Web content because we are concerned that there is
|
|
|
|
* a risk that users may unwittingly give Web content access to them
|
|
|
|
* and suffer undesirable consequences. The details of what is
|
|
|
|
* filtered out can be found in GetDirectoryListingTask::Work.
|
|
|
|
*
|
|
|
|
* In future, we will likely support filtering based on filename extensions
|
|
|
|
* (for example, aFilters could be "*.jpg; *.jpeg; *.gif"), but that isn't
|
|
|
|
* supported yet. Once supported, files that don't match a specified
|
|
|
|
* extension (if any are specified) would be filtered out. This
|
|
|
|
* functionality would allow us to apply the 'accept' attribute from
|
|
|
|
* <input type=file directory accept="..."> to the results of a directory
|
|
|
|
* picker operation.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
SetContentFilters(const nsAString& aFilters);
|
|
|
|
|
2014-03-12 10:30:21 +04:00
|
|
|
FileSystemBase*
|
2016-03-20 13:56:10 +03:00
|
|
|
GetFileSystem(ErrorResult& aRv);
|
|
|
|
|
2016-11-23 15:02:10 +03:00
|
|
|
nsIFile*
|
|
|
|
GetInternalNsIFile() const
|
|
|
|
{
|
|
|
|
return mFile;
|
|
|
|
}
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
private:
|
2016-03-20 13:56:10 +03:00
|
|
|
Directory(nsISupports* aParent,
|
2016-04-18 10:32:30 +03:00
|
|
|
nsIFile* aFile,
|
2016-03-20 13:56:10 +03:00
|
|
|
FileSystemBase* aFileSystem = nullptr);
|
2014-06-23 23:56:07 +04:00
|
|
|
~Directory();
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
/*
|
|
|
|
* Convert relative DOM path to the absolute real path.
|
|
|
|
*/
|
2016-03-20 13:56:10 +03:00
|
|
|
nsresult
|
|
|
|
DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;
|
2014-03-05 07:25:40 +04:00
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<FileSystemBase> mFileSystem;
|
2016-03-20 13:56:10 +03:00
|
|
|
nsCOMPtr<nsIFile> mFile;
|
|
|
|
|
2015-10-09 17:59:40 +03:00
|
|
|
nsString mFilters;
|
2016-03-30 09:17:56 +03:00
|
|
|
nsString mPath;
|
2014-03-05 07:26:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Directory_h
|