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/. */
7 #ifndef mozilla_dom_Directory_h
8 #define mozilla_dom_Directory_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/dom/BindingDeclarations.h"
13 #include "mozilla/dom/File.h"
14 #include "nsAutoPtr.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsPIDOMWindow.h"
17 #include "nsWrapperCache.h"
19 // Resolve the name collision of Microsoft's API name with macros defined in
20 // Windows header files. Undefine the macro of CreateDirectory to avoid
21 // Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
22 #ifdef CreateDirectory
23 #undef CreateDirectory
25 // Undefine the macro of CreateFile to avoid Directory#CreateFile being replaced
26 // by Directory#CreateFileW.
34 struct CreateFileOptions
;
37 class StringOrFileOrDirectory
;
39 class Directory MOZ_FINAL
41 , public nsWrapperCache
44 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
45 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory
)
48 static already_AddRefed
<Promise
>
49 GetRoot(FileSystemBase
* aFileSystem
, ErrorResult
& aRv
);
51 Directory(FileSystemBase
* aFileSystem
, const nsAString
& aPath
);
53 // ========= Begin WebIDL bindings. ===========
56 GetParentObject() const;
59 WrapObject(JSContext
* aCx
) MOZ_OVERRIDE
;
62 GetName(nsString
& aRetval
) const;
64 already_AddRefed
<Promise
>
65 CreateFile(const nsAString
& aPath
, const CreateFileOptions
& aOptions
,
68 already_AddRefed
<Promise
>
69 CreateDirectory(const nsAString
& aPath
, ErrorResult
& aRv
);
71 already_AddRefed
<Promise
>
72 Get(const nsAString
& aPath
, ErrorResult
& aRv
);
74 already_AddRefed
<Promise
>
75 Remove(const StringOrFileOrDirectory
& aPath
, ErrorResult
& aRv
);
77 already_AddRefed
<Promise
>
78 RemoveDeep(const StringOrFileOrDirectory
& aPath
, ErrorResult
& aRv
);
80 // =========== End WebIDL bindings.============
83 GetFileSystem() const;
88 IsValidRelativePath(const nsString
& aPath
);
91 * Convert relative DOM path to the absolute real path.
92 * @return true if succeed. false if the DOM path is invalid.
95 DOMPathToRealPath(const nsAString
& aPath
, nsAString
& aRealPath
) const;
97 already_AddRefed
<Promise
>
98 RemoveInternal(const StringOrFileOrDirectory
& aPath
, bool aRecursive
,
101 nsRefPtr
<FileSystemBase
> mFileSystem
;
106 } // namespace mozilla
108 #endif // mozilla_dom_Directory_h