tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

FileSystemHandle.h (3358B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_FS_FILESYSTEMHANDLE_H_
      8 #define DOM_FS_FILESYSTEMHANDLE_H_
      9 
     10 #include "mozilla/dom/PFileSystemManager.h"
     11 #include "nsCOMPtr.h"
     12 #include "nsISupports.h"
     13 #include "nsWrapperCache.h"
     14 
     15 class nsIGlobalObject;
     16 
     17 namespace mozilla {
     18 
     19 class ErrorResult;
     20 
     21 namespace dom {
     22 
     23 class FileSystemDirectoryHandle;
     24 class FileSystemFileHandle;
     25 enum class FileSystemHandleKind : uint8_t;
     26 class FileSystemManager;
     27 class FileSystemManagerChild;
     28 class Promise;
     29 
     30 namespace fs {
     31 class FileSystemRequestHandler;
     32 }  // namespace fs
     33 
     34 class FileSystemHandle : public nsISupports, public nsWrapperCache {
     35 public:
     36  FileSystemHandle(nsIGlobalObject* aGlobal,
     37                   RefPtr<FileSystemManager>& aManager,
     38                   const fs::FileSystemEntryMetadata& aMetadata,
     39                   fs::FileSystemRequestHandler* aRequestHandler);
     40 
     41  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     42  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(FileSystemHandle)
     43 
     44  const fs::EntryId& GetId() const { return mMetadata.entryId(); }
     45 
     46  // WebIDL Boilerplate
     47  nsIGlobalObject* GetParentObject() const;
     48 
     49  JSObject* WrapObject(JSContext* aCx,
     50                       JS::Handle<JSObject*> aGivenProto) override;
     51 
     52  // WebIDL Interface
     53  virtual FileSystemHandleKind Kind() const = 0;
     54 
     55  void GetName(nsAString& aResult);
     56 
     57  already_AddRefed<Promise> IsSameEntry(FileSystemHandle& aOther,
     58                                        ErrorResult& aError) const;
     59 
     60  // [Serializable] implementation
     61  static already_AddRefed<FileSystemHandle> ReadStructuredClone(
     62      JSContext* aCx, nsIGlobalObject* aGlobal,
     63      JSStructuredCloneReader* aReader);
     64 
     65  virtual bool WriteStructuredClone(JSContext* aCx,
     66                                    JSStructuredCloneWriter* aWriter) const;
     67 
     68  already_AddRefed<Promise> Move(const nsAString& aName, ErrorResult& aError);
     69 
     70  already_AddRefed<Promise> Move(FileSystemDirectoryHandle& aParent,
     71                                 ErrorResult& aError);
     72 
     73  already_AddRefed<Promise> Move(FileSystemDirectoryHandle& aParent,
     74                                 const nsAString& aName, ErrorResult& aError);
     75 
     76  already_AddRefed<Promise> Move(const fs::EntryId& aParentId,
     77                                 const nsAString& aName, ErrorResult& aError);
     78 
     79  void UpdateMetadata(const fs::FileSystemEntryMetadata& aMetadata) {
     80    mMetadata = aMetadata;
     81  }
     82 
     83 protected:
     84  virtual ~FileSystemHandle() = default;
     85 
     86  static already_AddRefed<FileSystemFileHandle> ConstructFileHandle(
     87      JSContext* aCx, nsIGlobalObject* aGlobal,
     88      JSStructuredCloneReader* aReader);
     89 
     90  static already_AddRefed<FileSystemDirectoryHandle> ConstructDirectoryHandle(
     91      JSContext* aCx, nsIGlobalObject* aGlobal,
     92      JSStructuredCloneReader* aReader);
     93 
     94  nsCOMPtr<nsIGlobalObject> mGlobal;
     95 
     96  RefPtr<FileSystemManager> mManager;
     97 
     98  // move() can change names/directories
     99  fs::FileSystemEntryMetadata mMetadata;
    100 
    101  const UniquePtr<fs::FileSystemRequestHandler> mRequestHandler;
    102 };
    103 
    104 }  // namespace dom
    105 }  // namespace mozilla
    106 
    107 #endif  // DOM_FS_FILESYSTEMHANDLE_H_