dom/filesystem/Directory.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/dom/BindingDeclarations.h"
    12 #include "nsAutoPtr.h"
    13 #include "nsCycleCollectionParticipant.h"
    14 #include "nsDOMFile.h"
    15 #include "nsPIDOMWindow.h"
    16 #include "nsWrapperCache.h"
    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
    30 namespace mozilla {
    31 namespace dom {
    33 class CreateFileOptions;
    34 class FileSystemBase;
    35 class Promise;
    36 class StringOrFileOrDirectory;
    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)
    46 public:
    47   static already_AddRefed<Promise>
    48   GetRoot(FileSystemBase* aFileSystem);
    50   Directory(FileSystemBase* aFileSystem, const nsAString& aPath);
    51   ~Directory();
    53   // ========= Begin WebIDL bindings. ===========
    55   nsPIDOMWindow*
    56   GetParentObject() const;
    58   virtual JSObject*
    59   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    61   void
    62   GetName(nsString& aRetval) const;
    64   already_AddRefed<Promise>
    65   CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions);
    67   already_AddRefed<Promise>
    68   CreateDirectory(const nsAString& aPath);
    70   already_AddRefed<Promise>
    71   Get(const nsAString& aPath);
    73   already_AddRefed<Promise>
    74   Remove(const StringOrFileOrDirectory& aPath);
    76   already_AddRefed<Promise>
    77   RemoveDeep(const StringOrFileOrDirectory& aPath);
    79   // =========== End WebIDL bindings.============
    81   FileSystemBase*
    82   GetFileSystem() const;
    83 private:
    84   static bool
    85   IsValidRelativePath(const nsString& aPath);
    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;
    94   already_AddRefed<Promise>
    95   RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive);
    97   nsRefPtr<FileSystemBase> mFileSystem;
    98   nsString mPath;
    99 };
   101 } // namespace dom
   102 } // namespace mozilla
   104 #endif // mozilla_dom_Directory_h

mercurial