2014-03-05 03:26:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_Directory_h
|
|
|
|
#define mozilla_dom_Directory_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-07-19 01:31:11 +00:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-03-05 03:26:39 +00:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2014-10-08 16:15:23 +00:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-03-05 03:26:39 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
// Resolve the name collision of Microsoft's API name with macros defined in
|
|
|
|
// Windows header files. Undefine the macro of CreateDirectory to avoid
|
|
|
|
// Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
|
|
|
|
#ifdef CreateDirectory
|
|
|
|
#undef CreateDirectory
|
|
|
|
#endif
|
2014-03-05 08:40:48 +00:00
|
|
|
// Undefine the macro of CreateFile to avoid Directory#CreateFile being replaced
|
|
|
|
// by Directory#CreateFileW.
|
|
|
|
#ifdef CreateFile
|
|
|
|
#undef CreateFile
|
|
|
|
#endif
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-06-19 00:57:51 +00:00
|
|
|
struct CreateFileOptions;
|
2014-03-05 03:25:40 +00:00
|
|
|
class FileSystemBase;
|
2014-03-05 03:26:39 +00:00
|
|
|
class Promise;
|
2014-03-12 06:30:21 +00:00
|
|
|
class StringOrFileOrDirectory;
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
class Directory MOZ_FINAL
|
|
|
|
: public nsISupports
|
|
|
|
, public nsWrapperCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory)
|
|
|
|
|
|
|
|
public:
|
2014-03-05 03:25:40 +00:00
|
|
|
static already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
GetRoot(FileSystemBase* aFileSystem, ErrorResult& aRv);
|
2014-03-05 03:25:40 +00:00
|
|
|
|
|
|
|
Directory(FileSystemBase* aFileSystem, const nsAString& aPath);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
// ========= Begin WebIDL bindings. ===========
|
|
|
|
|
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const;
|
|
|
|
|
|
|
|
virtual JSObject*
|
2014-04-08 22:27:18 +00:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
GetName(nsString& aRetval) const;
|
|
|
|
|
2014-03-05 08:40:48 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2014-03-05 08:40:48 +00:00
|
|
|
|
2014-03-05 03:26:39 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
CreateDirectory(const nsAString& aPath, ErrorResult& aRv);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
Get(const nsAString& aPath, ErrorResult& aRv);
|
2014-03-05 03:26:39 +00:00
|
|
|
|
2014-03-12 06:30:21 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
2014-03-05 03:26:39 +00:00
|
|
|
// =========== End WebIDL bindings.============
|
2014-03-12 06:30:21 +00:00
|
|
|
|
|
|
|
FileSystemBase*
|
|
|
|
GetFileSystem() const;
|
2014-03-05 03:25:40 +00:00
|
|
|
private:
|
2014-06-23 19:56:07 +00:00
|
|
|
~Directory();
|
|
|
|
|
2014-03-05 03:25:40 +00:00
|
|
|
static bool
|
|
|
|
IsValidRelativePath(const nsString& aPath);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert relative DOM path to the absolute real path.
|
|
|
|
* @return true if succeed. false if the DOM path is invalid.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
DOMPathToRealPath(const nsAString& aPath, nsAString& aRealPath) const;
|
|
|
|
|
2014-03-12 06:30:21 +00:00
|
|
|
already_AddRefed<Promise>
|
2014-07-19 01:31:11 +00:00
|
|
|
RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
|
|
|
|
ErrorResult& aRv);
|
2014-03-12 06:30:21 +00:00
|
|
|
|
2014-03-05 03:25:40 +00:00
|
|
|
nsRefPtr<FileSystemBase> mFileSystem;
|
|
|
|
nsString mPath;
|
2014-03-05 03:26:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_Directory_h
|