2014-03-05 03:26:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-05 03:26:39 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Directory_h
|
|
|
|
#define mozilla_dom_Directory_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-07-19 01:31:11 +00:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-03-05 03:26:39 +00:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-10-08 16:15:23 +00:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-03-05 03:26:39 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
// Resolve the name collision of Microsoft's API name with macros defined in
|
|
|
|
// Windows header files. Undefine the macro of CreateDirectory to avoid
|
|
|
|
// Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
|
|
|
|
#ifdef CreateDirectory
|
|
|
|
#undef CreateDirectory
|
|
|
|
#endif
|
2014-03-05 08:40:48 +00:00
|
|
|
// Undefine the macro of CreateFile to avoid Directory#CreateFile being replaced
|
|
|
|
// by Directory#CreateFileW.
|
|
|
|
#ifdef CreateFile
|
|
|
|
#undef CreateFile
|
|
|
|
#endif
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-19 00:57:51 +00:00
|
|
|
struct CreateFileOptions;
|
2014-03-05 03:25:40 +00:00
|
|
|
class FileSystemBase;
|
2014-03-05 03:26:39 +00:00
|
|
|
class Promise;
|
2014-03-12 06:30:21 +00:00
|
|
|
class StringOrFileOrDirectory;
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class Directory final
|
2014-03-05 03:26:39 +00:00
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
2016-04-09 18:15:50 +00:00
|
|
|
struct FileOrDirectoryPath
|
2016-03-20 10:56:10 +00:00
|
|
|
{
|
2016-04-09 18:15:50 +00:00
|
|
|
nsString mPath;
|
2016-03-20 10:56:10 +00:00
|
|
|
|
|
|
|
enum {
|
2016-04-09 18:15:50 +00:00
|
|
|
eFilePath,
|
2016-03-20 10:56:10 +00:00
|
|
|
eDirectoryPath
|
|
|
|
} mType;
|
|
|
|
};
|
|
|
|
|
2014-03-05 03:26:39 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory)
|
|
|
|
|
2016-04-12 12:50:38 +00:00
|
|
|
static bool
|
|
|
|
DeviceStorageEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2016-05-13 11:11:38 +00:00
|
|
|
static bool
|
|
|
|
WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
2014-03-05 03:25:40 +00:00
|
|
|
static already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
GetRoot(FileSystemBase* aFileSystem, ErrorResult& aRv);
|
2014-03-05 03:25:40 +00:00
|
|
|
|
2016-06-01 10:29:00 +00:00
|
|
|
static already_AddRefed<Directory>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aRealPath,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
static already_AddRefed<Directory>
|
2016-03-20 10:56:10 +00:00
|
|
|
Create(nsISupports* aParent, nsIFile* aDirectory,
|
2016-04-18 07:32:30 +00:00
|
|
|
FileSystemBase* aFileSystem = 0);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
// ========= Begin WebIDL bindings. ===========
|
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
nsISupports*
|
2014-03-05 03:26:39 +00:00
|
|
|
GetParentObject() const;
|
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 16:28:04 +00:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
void
|
2016-03-20 10:56:10 +00:00
|
|
|
GetName(nsAString& aRetval, ErrorResult& aRv);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2014-03-05 08:40:48 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2014-03-05 08:40:48 +00:00
|
|
|
|
2014-03-05 03:26:39 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
CreateDirectory(const nsAString& aPath, ErrorResult& aRv);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
Get(const nsAString& aPath, ErrorResult& aRv);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2014-03-12 06:30:21 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
2015-06-22 23:31:34 +00:00
|
|
|
// From https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface :
|
|
|
|
|
|
|
|
void
|
2016-03-20 10:56:10 +00:00
|
|
|
GetPath(nsAString& aRetval, ErrorResult& aRv);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetFullRealPath(nsAString& aPath);
|
2015-06-22 23:31:34 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2016-03-20 10:56:10 +00:00
|
|
|
GetFilesAndDirectories(ErrorResult& aRv);
|
2015-06-22 23:31:34 +00:00
|
|
|
|
2016-04-13 11:15:56 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
GetFiles(bool aRecursiveFlag, ErrorResult& aRv);
|
|
|
|
|
2014-03-05 03:26:39 +00:00
|
|
|
// =========== End WebIDL bindings.============
|
2014-03-12 06:30:21 +00:00
|
|
|
|
2015-10-09 14:59:40 +00: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 06:30:21 +00:00
|
|
|
FileSystemBase*
|
2016-03-20 10:56:10 +00:00
|
|
|
GetFileSystem(ErrorResult& aRv);
|
|
|
|
|
2016-04-12 12:50:38 +00:00
|
|
|
bool
|
|
|
|
ClonableToDifferentThreadOrProcess() const;
|
|
|
|
|
2014-03-05 03:25:40 +00:00
|
|
|
private:
|
2016-03-20 10:56:10 +00:00
|
|
|
Directory(nsISupports* aParent,
|
2016-04-18 07:32:30 +00:00
|
|
|
nsIFile* aFile,
|
2016-03-20 10:56:10 +00:00
|
|
|
FileSystemBase* aFileSystem = nullptr);
|
2014-06-23 19:56:07 +00:00
|
|
|
~Directory();
|
|
|
|
|
2014-03-05 03:25:40 +00:00
|
|
|
/*
|
|
|
|
* Convert relative DOM path to the absolute real path.
|
|
|
|
*/
|
2016-03-20 10:56:10 +00:00
|
|
|
nsresult
|
|
|
|
DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;
|
2014-03-05 03:25:40 +00:00
|
|
|
|
2014-03-12 06:30:21 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
|
|
|
|
ErrorResult& aRv);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
nsCOMPtr<nsISupports> mParent;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<FileSystemBase> mFileSystem;
|
2016-03-20 10:56:10 +00:00
|
|
|
nsCOMPtr<nsIFile> mFile;
|
|
|
|
|
2015-10-09 14:59:40 +00:00
|
|
|
nsString mFilters;
|
2016-03-30 06:17:56 +00:00
|
|
|
nsString mPath;
|
2014-03-05 03:26:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Directory_h
|