Bug 1892041 - Part 1: Update test262 features. r=spidermonkey-reviewers,dminor
[gecko.git] / dom / filesystem / Directory.h
blobb8ee0e68e1f6ad982fca4e883be4b40b6111b679
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_Directory_h
8 #define mozilla_dom_Directory_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/BindingDeclarations.h"
12 #include "mozilla/dom/File.h"
13 #include "nsCycleCollectionParticipant.h"
14 #include "nsWrapperCache.h"
16 namespace mozilla {
17 class ErrorResult;
19 namespace dom {
21 class FileSystemBase;
22 class Promise;
23 class StringOrFileOrDirectory;
25 class Directory final : public nsISupports, public nsWrapperCache {
26 public:
27 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
28 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Directory)
30 static already_AddRefed<Directory> Constructor(const GlobalObject& aGlobal,
31 const nsAString& aRealPath,
32 ErrorResult& aRv);
34 static already_AddRefed<Directory> Create(nsIGlobalObject* aGlobal,
35 nsIFile* aDirectory,
36 FileSystemBase* aFileSystem = 0);
38 // ========= Begin WebIDL bindings. ===========
40 nsIGlobalObject* GetParentObject() const;
42 virtual JSObject* WrapObject(JSContext* aCx,
43 JS::Handle<JSObject*> aGivenProto) override;
45 void GetName(nsAString& aRetval, ErrorResult& aRv);
47 // From
48 // https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface
49 // :
51 void GetPath(nsAString& aRetval, ErrorResult& aRv);
53 nsresult GetFullRealPath(nsAString& aPath);
55 already_AddRefed<Promise> GetFilesAndDirectories(ErrorResult& aRv);
57 already_AddRefed<Promise> GetFiles(bool aRecursiveFlag, ErrorResult& aRv);
59 // =========== End WebIDL bindings.============
61 /**
62 * Sets a semi-colon separated list of filters to filter-in or filter-out
63 * certain types of files when the contents of this directory are requested
64 * via a GetFilesAndDirectories() call.
66 * Currently supported keywords:
68 * * filter-out-sensitive
69 * This keyword filters out files or directories that we don't wish to
70 * make available to Web content because we are concerned that there is
71 * a risk that users may unwittingly give Web content access to them
72 * and suffer undesirable consequences. The details of what is
73 * filtered out can be found in GetDirectoryListingTask::Work.
75 * In future, we will likely support filtering based on filename extensions
76 * (for example, aFilters could be "*.jpg; *.jpeg; *.gif"), but that isn't
77 * supported yet. Once supported, files that don't match a specified
78 * extension (if any are specified) would be filtered out. This
79 * functionality would allow us to apply the 'accept' attribute from
80 * <input type=file directory accept="..."> to the results of a directory
81 * picker operation.
83 void SetContentFilters(const nsAString& aFilters);
85 FileSystemBase* GetFileSystem(ErrorResult& aRv);
87 nsIFile* GetInternalNsIFile() const { return mFile; }
89 private:
90 Directory(nsIGlobalObject* aGlobal, nsIFile* aFile,
91 FileSystemBase* aFileSystem = nullptr);
92 ~Directory();
95 * Convert relative DOM path to the absolute real path.
97 nsresult DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;
99 nsCOMPtr<nsIGlobalObject> mGlobal;
100 RefPtr<FileSystemBase> mFileSystem;
101 nsCOMPtr<nsIFile> mFile;
103 nsString mFilters;
104 nsString mPath;
107 } // namespace dom
108 } // namespace mozilla
110 #endif // mozilla_dom_Directory_h