2015-07-10 20:54:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/OSFileSystem.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/Directory.h"
|
|
|
|
#include "mozilla/dom/File.h"
|
|
|
|
#include "mozilla/dom/FileSystemUtils.h"
|
2016-03-20 13:56:10 +03:00
|
|
|
#include "nsIGlobalObject.h"
|
2015-07-10 20:54:53 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
OSFileSystem::OSFileSystem(const nsAString& aRootDir) {
|
2017-03-08 22:15:45 +03:00
|
|
|
mLocalRootPath = aRootDir;
|
2015-07-10 20:54:53 +03:00
|
|
|
}
|
|
|
|
|
2016-03-20 13:58:01 +03:00
|
|
|
already_AddRefed<FileSystemBase> OSFileSystem::Clone() {
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2017-03-08 22:15:45 +03:00
|
|
|
RefPtr<OSFileSystem> fs = new OSFileSystem(mLocalRootPath);
|
2019-10-21 08:33:33 +03:00
|
|
|
if (mGlobal) {
|
|
|
|
fs->Init(mGlobal);
|
2016-03-20 13:58:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return fs.forget();
|
|
|
|
}
|
|
|
|
|
2019-10-21 08:33:33 +03:00
|
|
|
void OSFileSystem::Init(nsIGlobalObject* aGlobal) {
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-10-21 08:33:33 +03:00
|
|
|
MOZ_ASSERT(!mGlobal, "No duple Init() calls");
|
|
|
|
MOZ_ASSERT(aGlobal);
|
2016-04-09 21:17:02 +03:00
|
|
|
|
2019-10-21 08:33:33 +03:00
|
|
|
mGlobal = aGlobal;
|
2015-07-10 20:54:53 +03:00
|
|
|
}
|
|
|
|
|
2019-10-21 08:33:33 +03:00
|
|
|
nsIGlobalObject* OSFileSystem::GetParentObject() const {
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-10-21 08:33:33 +03:00
|
|
|
return mGlobal;
|
2015-07-10 20:54:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OSFileSystem::IsSafeFile(nsIFile* aFile) const {
|
|
|
|
// The concept of "safe files" is specific to the Device Storage API where
|
|
|
|
// files are only "safe" if they're of a type that is appropriate for the
|
|
|
|
// area of device storage that is being used.
|
|
|
|
MOZ_CRASH("Don't use OSFileSystem with the Device Storage API");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSFileSystem::IsSafeDirectory(Directory* aDir) const {
|
|
|
|
// The concept of "safe directory" is specific to the Device Storage API
|
|
|
|
// where a directory is only "safe" if it belongs to the area of device
|
|
|
|
// storage that it is being used with.
|
|
|
|
MOZ_CRASH("Don't use OSFileSystem with the Device Storage API");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-30 11:53:38 +03:00
|
|
|
void OSFileSystem::Unlink() {
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2019-10-21 08:33:33 +03:00
|
|
|
mGlobal = nullptr;
|
2015-12-30 11:53:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSFileSystem::Traverse(nsCycleCollectionTraversalCallback& cb) {
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2015-12-30 11:53:38 +03:00
|
|
|
OSFileSystem* tmp = this;
|
2019-10-21 08:33:33 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal);
|
2016-03-20 00:29:46 +03:00
|
|
|
}
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
void OSFileSystem::SerializeDOMPath(nsAString& aOutput) const {
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2017-03-08 22:15:45 +03:00
|
|
|
aOutput = mLocalRootPath;
|
2016-03-20 13:56:10 +03:00
|
|
|
}
|
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
/**
|
|
|
|
* OSFileSystemParent
|
|
|
|
*/
|
|
|
|
|
|
|
|
OSFileSystemParent::OSFileSystemParent(const nsAString& aRootDir) {
|
2017-03-08 22:15:45 +03:00
|
|
|
mLocalRootPath = aRootDir;
|
2016-04-09 21:17:02 +03:00
|
|
|
}
|
|
|
|
|
2015-07-10 20:54:53 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|