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_GetDirectoryListing_h
8 : #define mozilla_dom_GetDirectoryListing_h
9 :
10 : #include "mozilla/dom/Directory.h"
11 : #include "mozilla/dom/FileSystemTaskBase.h"
12 : #include "mozilla/ErrorResult.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 : class BlobImpl;
18 : class FileSystemGetDirectoryListingParams;
19 : class OwningFileOrDirectory;
20 :
21 : class GetDirectoryListingTaskChild final : public FileSystemTaskChildBase
22 : {
23 : public:
24 : static already_AddRefed<GetDirectoryListingTaskChild>
25 : Create(FileSystemBase* aFileSystem,
26 : Directory* aDirectory,
27 : nsIFile* aTargetPath,
28 : const nsAString& aFilters,
29 : ErrorResult& aRv);
30 :
31 : virtual
32 : ~GetDirectoryListingTaskChild();
33 :
34 : already_AddRefed<Promise>
35 : GetPromise();
36 :
37 : private:
38 : // If aDirectoryOnly is set, we should ensure that the target is a directory.
39 : GetDirectoryListingTaskChild(nsIGlobalObject* aGlobalObject,
40 : FileSystemBase* aFileSystem,
41 : Directory* aDirectory,
42 : nsIFile* aTargetPath,
43 : const nsAString& aFilters);
44 :
45 : virtual FileSystemParams
46 : GetRequestParams(const nsString& aSerializedDOMPath,
47 : ErrorResult& aRv) const override;
48 :
49 : virtual void
50 : SetSuccessRequestResult(const FileSystemResponseValue& aValue,
51 : ErrorResult& aRv) override;
52 :
53 : virtual void
54 : HandlerCallback() override;
55 :
56 : RefPtr<Promise> mPromise;
57 : RefPtr<Directory> mDirectory;
58 : nsCOMPtr<nsIFile> mTargetPath;
59 : nsString mFilters;
60 :
61 : FallibleTArray<OwningFileOrDirectory> mTargetData;
62 : };
63 :
64 0 : class GetDirectoryListingTaskParent final : public FileSystemTaskParentBase
65 : {
66 : public:
67 : static already_AddRefed<GetDirectoryListingTaskParent>
68 : Create(FileSystemBase* aFileSystem,
69 : const FileSystemGetDirectoryListingParams& aParam,
70 : FileSystemRequestParent* aParent,
71 : ErrorResult& aRv);
72 :
73 : nsresult
74 : GetTargetPath(nsAString& aPath) const override;
75 :
76 : private:
77 : GetDirectoryListingTaskParent(FileSystemBase* aFileSystem,
78 : const FileSystemGetDirectoryListingParams& aParam,
79 : FileSystemRequestParent* aParent);
80 :
81 : virtual FileSystemResponseValue
82 : GetSuccessRequestResult(ErrorResult& aRv) const override;
83 :
84 : virtual nsresult
85 : IOWork() override;
86 :
87 : nsCOMPtr<nsIFile> mTargetPath;
88 : nsString mDOMPath;
89 : nsString mFilters;
90 :
91 0 : struct FileOrDirectoryPath
92 : {
93 : nsString mPath;
94 :
95 : enum {
96 : eFilePath,
97 : eDirectoryPath
98 : } mType;
99 : };
100 :
101 : FallibleTArray<FileOrDirectoryPath> mTargetData;
102 : };
103 :
104 : } // namespace dom
105 : } // namespace mozilla
106 :
107 : #endif // mozilla_dom_GetDirectoryListing_h
|