2014-03-05 07:25:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-05 07:25:40 +04:00
|
|
|
/* 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/FileSystemBase.h"
|
|
|
|
|
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2015-07-10 20:54:53 +03:00
|
|
|
#include "OSFileSystem.h"
|
2014-03-05 07:25:40 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
FileSystemBase::FileSystemBase()
|
|
|
|
: mShutdown(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FileSystemBase::~FileSystemBase()
|
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-03-05 07:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FileSystemBase::Shutdown()
|
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-03-05 07:25:40 +04:00
|
|
|
mShutdown = true;
|
|
|
|
}
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
nsISupports*
|
|
|
|
FileSystemBase::GetParentObject() const
|
2014-03-05 07:25:40 +04:00
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-03-05 07:25:40 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-10 20:54:53 +03:00
|
|
|
bool
|
2016-03-20 13:56:10 +03:00
|
|
|
FileSystemBase::GetRealPath(BlobImpl* aFile, nsIFile** aPath) const
|
2015-07-10 20:54:53 +03:00
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2015-07-10 20:54:53 +03:00
|
|
|
MOZ_ASSERT(aFile, "aFile Should not be null.");
|
2016-04-09 21:15:50 +03:00
|
|
|
MOZ_ASSERT(aPath);
|
2015-07-10 20:54:53 +03:00
|
|
|
|
|
|
|
nsAutoString filePath;
|
|
|
|
ErrorResult rv;
|
|
|
|
aFile->GetMozFullPathInternal(filePath, rv);
|
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
2016-07-22 17:50:10 +03:00
|
|
|
rv.SuppressException();
|
2015-07-10 20:54:53 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 06:48:29 +03:00
|
|
|
rv = NS_NewLocalFile(filePath, true, aPath);
|
2016-03-20 13:56:10 +03:00
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
2016-07-22 17:50:10 +03:00
|
|
|
rv.SuppressException();
|
2016-03-20 13:56:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2015-07-10 20:54:53 +03:00
|
|
|
}
|
|
|
|
|
2014-03-05 07:24:19 +04:00
|
|
|
bool
|
|
|
|
FileSystemBase::IsSafeFile(nsIFile* aFile) const
|
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-03-05 07:24:19 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-12 10:30:21 +04:00
|
|
|
bool
|
|
|
|
FileSystemBase::IsSafeDirectory(Directory* aDir) const
|
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-03-12 10:30:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-18 10:32:30 +03:00
|
|
|
void
|
|
|
|
FileSystemBase::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
|
|
|
|
ErrorResult& aRv) const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aFile);
|
|
|
|
|
|
|
|
aRv = aFile->GetLeafName(aRetval);
|
2016-09-02 10:12:24 +03:00
|
|
|
NS_WARNING_ASSERTION(!aRv.Failed(), "GetLeafName failed");
|
2016-04-18 10:32:30 +03:00
|
|
|
}
|
|
|
|
|
2016-03-30 09:17:56 +03:00
|
|
|
void
|
|
|
|
FileSystemBase::GetDOMPath(nsIFile* aFile,
|
|
|
|
nsAString& aRetval,
|
|
|
|
ErrorResult& aRv) const
|
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnOwningThread();
|
2016-03-30 09:17:56 +03:00
|
|
|
MOZ_ASSERT(aFile);
|
|
|
|
|
2016-04-18 10:32:30 +03:00
|
|
|
aRetval.Truncate();
|
2016-03-30 09:17:56 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> fileSystemPath;
|
2017-03-08 22:15:45 +03:00
|
|
|
aRv = NS_NewLocalFile(LocalRootPath(), true, getter_AddRefs(fileSystemPath));
|
2016-03-30 09:17:56 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> path;
|
|
|
|
aRv = aFile->Clone(getter_AddRefs(path));
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsString> parts;
|
|
|
|
|
|
|
|
while (true) {
|
2016-04-18 10:32:30 +03:00
|
|
|
nsAutoString leafName;
|
|
|
|
aRv = path->GetLeafName(leafName);
|
2016-03-30 09:17:56 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-13 18:20:26 +03:00
|
|
|
if (!leafName.IsEmpty()) {
|
|
|
|
parts.AppendElement(leafName);
|
|
|
|
}
|
2016-03-30 09:17:56 +03:00
|
|
|
|
2016-04-18 10:32:30 +03:00
|
|
|
bool equal = false;
|
|
|
|
aRv = fileSystemPath->Equals(path, &equal);
|
2016-03-30 09:17:56 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-18 10:32:30 +03:00
|
|
|
if (equal) {
|
|
|
|
break;
|
|
|
|
}
|
2016-03-30 09:17:56 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> parentPath;
|
|
|
|
aRv = path->GetParent(getter_AddRefs(parentPath));
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(parentPath);
|
|
|
|
|
|
|
|
aRv = parentPath->Clone(getter_AddRefs(path));
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 18:20:26 +03:00
|
|
|
if (parts.IsEmpty()) {
|
|
|
|
aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-30 09:17:56 +03:00
|
|
|
|
|
|
|
for (int32_t i = parts.Length() - 1; i >= 0; --i) {
|
|
|
|
aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
|
|
|
|
aRetval.Append(parts[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
void
|
|
|
|
FileSystemBase::AssertIsOnOwningThread() const
|
|
|
|
{
|
2017-05-03 18:48:54 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(FileSystemBase);
|
2016-04-09 21:17:02 +03:00
|
|
|
}
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|