OSFileSystem.h (2964B)
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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_OSFileSystem_h 8 #define mozilla_dom_OSFileSystem_h 9 10 #include "mozilla/dom/FileSystemBase.h" 11 12 namespace mozilla::dom { 13 14 class OSFileSystem final : public FileSystemBase { 15 public: 16 explicit OSFileSystem(const nsAString& aRootDir); 17 18 void Init(nsIGlobalObject* aGlobal); 19 20 // Overrides FileSystemBase 21 22 virtual already_AddRefed<FileSystemBase> Clone() override; 23 24 virtual bool ShouldCreateDirectory() override { 25 MOZ_CRASH("This should not be called."); 26 // Because OSFileSystem should not be used when the creation of directories 27 // is needed. For that we have OSFileSystemParent. 28 return false; 29 } 30 31 virtual nsIGlobalObject* GetParentObject() const override; 32 33 virtual bool IsSafeFile(nsIFile* aFile) const override; 34 35 virtual bool IsSafeDirectory(Directory* aDir) const override; 36 37 virtual void SerializeDOMPath(nsAString& aOutput) const override; 38 39 // CC methods 40 virtual void Unlink() override; 41 virtual void Traverse(nsCycleCollectionTraversalCallback& cb) override; 42 43 private: 44 virtual ~OSFileSystem() = default; 45 46 nsCOMPtr<nsIGlobalObject> mGlobal; 47 }; 48 49 class OSFileSystemParent final : public FileSystemBase { 50 public: 51 explicit OSFileSystemParent(const nsAString& aRootDir); 52 53 // Overrides FileSystemBase 54 55 virtual already_AddRefed<FileSystemBase> Clone() override { 56 MOZ_CRASH("This should not be called on the PBackground thread."); 57 return nullptr; 58 } 59 60 virtual bool ShouldCreateDirectory() override { return false; } 61 62 virtual nsIGlobalObject* GetParentObject() const override { 63 MOZ_CRASH("This should not be called on the PBackground thread."); 64 return nullptr; 65 } 66 67 virtual void GetDirectoryName(nsIFile* aFile, nsAString& aRetval, 68 ErrorResult& aRv) const override { 69 MOZ_CRASH("This should not be called on the PBackground thread."); 70 } 71 72 virtual bool IsSafeFile(nsIFile* aFile) const override { return true; } 73 74 virtual bool IsSafeDirectory(Directory* aDir) const override { 75 MOZ_CRASH("This should not be called on the PBackground thread."); 76 return true; 77 } 78 79 virtual void SerializeDOMPath(nsAString& aOutput) const override { 80 MOZ_CRASH("This should not be called on the PBackground thread."); 81 } 82 83 // CC methods 84 virtual void Unlink() override { 85 MOZ_CRASH("This should not be called on the PBackground thread."); 86 } 87 88 virtual void Traverse(nsCycleCollectionTraversalCallback& cb) override { 89 MOZ_CRASH("This should not be called on the PBackground thread."); 90 } 91 92 private: 93 virtual ~OSFileSystemParent() = default; 94 }; 95 96 } // namespace mozilla::dom 97 98 #endif // mozilla_dom_OSFileSystem_h