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"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
namespace mozilla {
|
2020-11-23 16:12:02 +00:00
|
|
|
class ErrorResult;
|
|
|
|
|
2014-03-05 03:26:39 +00:00
|
|
|
namespace dom {
|
|
|
|
|
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
|
|
|
|
|
|
|
class Directory final : public nsISupports, public nsWrapperCache {
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2022-09-07 11:22:51 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Directory)
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2016-06-01 10:29:00 +00:00
|
|
|
static already_AddRefed<Directory> Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aRealPath,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2019-10-21 05:33:33 +00:00
|
|
|
static already_AddRefed<Directory> Create(nsIGlobalObject* aGlobal,
|
2016-03-20 10:56:10 +00:00
|
|
|
nsIFile* aDirectory,
|
2016-04-18 07:32:30 +00:00
|
|
|
FileSystemBase* aFileSystem = 0);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
// ========= Begin WebIDL bindings. ===========
|
|
|
|
|
2019-10-21 05:33:33 +00:00
|
|
|
nsIGlobalObject* GetParentObject() const;
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
void GetName(nsAString& aRetval, ErrorResult& aRv);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2015-06-22 23:31:34 +00:00
|
|
|
// From
|
|
|
|
// https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface
|
|
|
|
// :
|
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
void GetPath(nsAString& aRetval, ErrorResult& aRv);
|
|
|
|
|
|
|
|
nsresult GetFullRealPath(nsAString& aPath);
|
2015-06-22 23:31:34 +00:00
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
already_AddRefed<Promise> 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);
|
|
|
|
|
2016-03-20 10:56:10 +00:00
|
|
|
FileSystemBase* GetFileSystem(ErrorResult& aRv);
|
|
|
|
|
2016-11-23 12:02:10 +00:00
|
|
|
nsIFile* GetInternalNsIFile() const { return mFile; }
|
|
|
|
|
2014-03-05 03:25:40 +00:00
|
|
|
private:
|
2019-10-21 05:33:33 +00:00
|
|
|
Directory(nsIGlobalObject* aGlobal, 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
|
|
|
|
2019-10-21 05:33:33 +00:00
|
|
|
nsCOMPtr<nsIGlobalObject> mGlobal;
|
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
|