|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=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/dom/BindingDeclarations.h" |
|
12 #include "nsAutoPtr.h" |
|
13 #include "nsCycleCollectionParticipant.h" |
|
14 #include "nsDOMFile.h" |
|
15 #include "nsPIDOMWindow.h" |
|
16 #include "nsWrapperCache.h" |
|
17 |
|
18 // Resolve the name collision of Microsoft's API name with macros defined in |
|
19 // Windows header files. Undefine the macro of CreateDirectory to avoid |
|
20 // Directory#CreateDirectory being replaced by Directory#CreateDirectoryW. |
|
21 #ifdef CreateDirectory |
|
22 #undef CreateDirectory |
|
23 #endif |
|
24 // Undefine the macro of CreateFile to avoid Directory#CreateFile being replaced |
|
25 // by Directory#CreateFileW. |
|
26 #ifdef CreateFile |
|
27 #undef CreateFile |
|
28 #endif |
|
29 |
|
30 namespace mozilla { |
|
31 namespace dom { |
|
32 |
|
33 class CreateFileOptions; |
|
34 class FileSystemBase; |
|
35 class Promise; |
|
36 class StringOrFileOrDirectory; |
|
37 |
|
38 class Directory MOZ_FINAL |
|
39 : public nsISupports |
|
40 , public nsWrapperCache |
|
41 { |
|
42 public: |
|
43 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
44 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory) |
|
45 |
|
46 public: |
|
47 static already_AddRefed<Promise> |
|
48 GetRoot(FileSystemBase* aFileSystem); |
|
49 |
|
50 Directory(FileSystemBase* aFileSystem, const nsAString& aPath); |
|
51 ~Directory(); |
|
52 |
|
53 // ========= Begin WebIDL bindings. =========== |
|
54 |
|
55 nsPIDOMWindow* |
|
56 GetParentObject() const; |
|
57 |
|
58 virtual JSObject* |
|
59 WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
60 |
|
61 void |
|
62 GetName(nsString& aRetval) const; |
|
63 |
|
64 already_AddRefed<Promise> |
|
65 CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions); |
|
66 |
|
67 already_AddRefed<Promise> |
|
68 CreateDirectory(const nsAString& aPath); |
|
69 |
|
70 already_AddRefed<Promise> |
|
71 Get(const nsAString& aPath); |
|
72 |
|
73 already_AddRefed<Promise> |
|
74 Remove(const StringOrFileOrDirectory& aPath); |
|
75 |
|
76 already_AddRefed<Promise> |
|
77 RemoveDeep(const StringOrFileOrDirectory& aPath); |
|
78 |
|
79 // =========== End WebIDL bindings.============ |
|
80 |
|
81 FileSystemBase* |
|
82 GetFileSystem() const; |
|
83 private: |
|
84 static bool |
|
85 IsValidRelativePath(const nsString& aPath); |
|
86 |
|
87 /* |
|
88 * Convert relative DOM path to the absolute real path. |
|
89 * @return true if succeed. false if the DOM path is invalid. |
|
90 */ |
|
91 bool |
|
92 DOMPathToRealPath(const nsAString& aPath, nsAString& aRealPath) const; |
|
93 |
|
94 already_AddRefed<Promise> |
|
95 RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive); |
|
96 |
|
97 nsRefPtr<FileSystemBase> mFileSystem; |
|
98 nsString mPath; |
|
99 }; |
|
100 |
|
101 } // namespace dom |
|
102 } // namespace mozilla |
|
103 |
|
104 #endif // mozilla_dom_Directory_h |