Line data Source code
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/. */
6 :
7 : #ifndef mozilla_dom_Directory_h
8 : #define mozilla_dom_Directory_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/ErrorResult.h"
12 : #include "mozilla/dom/BindingDeclarations.h"
13 : #include "mozilla/dom/File.h"
14 : #include "nsCycleCollectionParticipant.h"
15 : #include "nsWrapperCache.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 : class FileSystemBase;
21 : class Promise;
22 : class StringOrFileOrDirectory;
23 :
24 : class Directory final
25 : : public nsISupports
26 : , public nsWrapperCache
27 : {
28 : public:
29 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
30 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory)
31 :
32 : static bool
33 : WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj);
34 :
35 : static already_AddRefed<Directory>
36 : Constructor(const GlobalObject& aGlobal,
37 : const nsAString& aRealPath,
38 : ErrorResult& aRv);
39 :
40 : static already_AddRefed<Directory>
41 : Create(nsISupports* aParent, nsIFile* aDirectory,
42 : FileSystemBase* aFileSystem = 0);
43 :
44 : // ========= Begin WebIDL bindings. ===========
45 :
46 : nsISupports*
47 : GetParentObject() const;
48 :
49 : virtual JSObject*
50 : WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
51 :
52 : void
53 : GetName(nsAString& aRetval, ErrorResult& aRv);
54 :
55 : // From https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface :
56 :
57 : void
58 : GetPath(nsAString& aRetval, ErrorResult& aRv);
59 :
60 : nsresult
61 : GetFullRealPath(nsAString& aPath);
62 :
63 : already_AddRefed<Promise>
64 : GetFilesAndDirectories(ErrorResult& aRv);
65 :
66 : already_AddRefed<Promise>
67 : GetFiles(bool aRecursiveFlag, ErrorResult& aRv);
68 :
69 : // =========== End WebIDL bindings.============
70 :
71 : /**
72 : * Sets a semi-colon separated list of filters to filter-in or filter-out
73 : * certain types of files when the contents of this directory are requested
74 : * via a GetFilesAndDirectories() call.
75 : *
76 : * Currently supported keywords:
77 : *
78 : * * filter-out-sensitive
79 : * This keyword filters out files or directories that we don't wish to
80 : * make available to Web content because we are concerned that there is
81 : * a risk that users may unwittingly give Web content access to them
82 : * and suffer undesirable consequences. The details of what is
83 : * filtered out can be found in GetDirectoryListingTask::Work.
84 : *
85 : * In future, we will likely support filtering based on filename extensions
86 : * (for example, aFilters could be "*.jpg; *.jpeg; *.gif"), but that isn't
87 : * supported yet. Once supported, files that don't match a specified
88 : * extension (if any are specified) would be filtered out. This
89 : * functionality would allow us to apply the 'accept' attribute from
90 : * <input type=file directory accept="..."> to the results of a directory
91 : * picker operation.
92 : */
93 : void
94 : SetContentFilters(const nsAString& aFilters);
95 :
96 : FileSystemBase*
97 : GetFileSystem(ErrorResult& aRv);
98 :
99 : nsIFile*
100 0 : GetInternalNsIFile() const
101 : {
102 0 : return mFile;
103 : }
104 :
105 : private:
106 : Directory(nsISupports* aParent,
107 : nsIFile* aFile,
108 : FileSystemBase* aFileSystem = nullptr);
109 : ~Directory();
110 :
111 : /*
112 : * Convert relative DOM path to the absolute real path.
113 : */
114 : nsresult
115 : DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;
116 :
117 : nsCOMPtr<nsISupports> mParent;
118 : RefPtr<FileSystemBase> mFileSystem;
119 : nsCOMPtr<nsIFile> mFile;
120 :
121 : nsString mFilters;
122 : nsString mPath;
123 : };
124 :
125 : } // namespace dom
126 : } // namespace mozilla
127 :
128 : #endif // mozilla_dom_Directory_h
|