OSFileSystem.cpp (2397B)
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 #include "mozilla/dom/OSFileSystem.h" 8 9 #include "mozilla/dom/Directory.h" 10 #include "mozilla/dom/File.h" 11 #include "mozilla/dom/FileSystemUtils.h" 12 #include "nsCOMPtr.h" 13 #include "nsDebug.h" 14 #include "nsIFile.h" 15 #include "nsIGlobalObject.h" 16 17 namespace mozilla::dom { 18 19 OSFileSystem::OSFileSystem(const nsAString& aRootDir) { 20 mLocalRootPath = aRootDir; 21 } 22 23 already_AddRefed<FileSystemBase> OSFileSystem::Clone() { 24 AssertIsOnOwningThread(); 25 26 RefPtr<OSFileSystem> fs = new OSFileSystem(mLocalRootPath); 27 if (mGlobal) { 28 fs->Init(mGlobal); 29 } 30 31 return fs.forget(); 32 } 33 34 void OSFileSystem::Init(nsIGlobalObject* aGlobal) { 35 AssertIsOnOwningThread(); 36 MOZ_ASSERT(!mGlobal, "No duple Init() calls"); 37 MOZ_ASSERT(aGlobal); 38 39 mGlobal = aGlobal; 40 } 41 42 nsIGlobalObject* OSFileSystem::GetParentObject() const { 43 AssertIsOnOwningThread(); 44 return mGlobal; 45 } 46 47 bool OSFileSystem::IsSafeFile(nsIFile* aFile) const { 48 // The concept of "safe files" is specific to the Device Storage API where 49 // files are only "safe" if they're of a type that is appropriate for the 50 // area of device storage that is being used. 51 MOZ_CRASH("Don't use OSFileSystem with the Device Storage API"); 52 return true; 53 } 54 55 bool OSFileSystem::IsSafeDirectory(Directory* aDir) const { 56 // The concept of "safe directory" is specific to the Device Storage API 57 // where a directory is only "safe" if it belongs to the area of device 58 // storage that it is being used with. 59 MOZ_CRASH("Don't use OSFileSystem with the Device Storage API"); 60 return true; 61 } 62 63 void OSFileSystem::Unlink() { 64 AssertIsOnOwningThread(); 65 mGlobal = nullptr; 66 } 67 68 void OSFileSystem::Traverse(nsCycleCollectionTraversalCallback& cb) { 69 AssertIsOnOwningThread(); 70 71 OSFileSystem* tmp = this; 72 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal); 73 } 74 75 void OSFileSystem::SerializeDOMPath(nsAString& aOutput) const { 76 AssertIsOnOwningThread(); 77 aOutput = mLocalRootPath; 78 } 79 80 /** 81 * OSFileSystemParent 82 */ 83 84 OSFileSystemParent::OSFileSystemParent(const nsAString& aRootDir) { 85 mLocalRootPath = aRootDir; 86 } 87 88 } // namespace mozilla::dom