summaryrefslogtreecommitdiffstats
path: root/dom/filesystem/FileSystemBase.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/filesystem/FileSystemBase.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/filesystem/FileSystemBase.cpp')
-rw-r--r--dom/filesystem/FileSystemBase.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/dom/filesystem/FileSystemBase.cpp b/dom/filesystem/FileSystemBase.cpp
new file mode 100644
index 000000000..f44f4fbf1
--- /dev/null
+++ b/dom/filesystem/FileSystemBase.cpp
@@ -0,0 +1,169 @@
+/* -*- 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/FileSystemBase.h"
+
+#include "nsCharSeparatedTokenizer.h"
+#include "OSFileSystem.h"
+
+namespace mozilla {
+namespace dom {
+
+FileSystemBase::FileSystemBase()
+ : mShutdown(false)
+#ifdef DEBUG
+ , mOwningThread(PR_GetCurrentThread())
+#endif
+{
+}
+
+FileSystemBase::~FileSystemBase()
+{
+ AssertIsOnOwningThread();
+}
+
+void
+FileSystemBase::Shutdown()
+{
+ AssertIsOnOwningThread();
+ mShutdown = true;
+}
+
+nsISupports*
+FileSystemBase::GetParentObject() const
+{
+ AssertIsOnOwningThread();
+ return nullptr;
+}
+
+bool
+FileSystemBase::GetRealPath(BlobImpl* aFile, nsIFile** aPath) const
+{
+ AssertIsOnOwningThread();
+ MOZ_ASSERT(aFile, "aFile Should not be null.");
+ MOZ_ASSERT(aPath);
+
+ nsAutoString filePath;
+ ErrorResult rv;
+ aFile->GetMozFullPathInternal(filePath, rv);
+ if (NS_WARN_IF(rv.Failed())) {
+ rv.SuppressException();
+ return false;
+ }
+
+ rv = NS_NewLocalFile(filePath, true, aPath);
+ if (NS_WARN_IF(rv.Failed())) {
+ rv.SuppressException();
+ return false;
+ }
+
+ return true;
+}
+
+bool
+FileSystemBase::IsSafeFile(nsIFile* aFile) const
+{
+ AssertIsOnOwningThread();
+ return false;
+}
+
+bool
+FileSystemBase::IsSafeDirectory(Directory* aDir) const
+{
+ AssertIsOnOwningThread();
+ return false;
+}
+
+void
+FileSystemBase::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
+ ErrorResult& aRv) const
+{
+ AssertIsOnOwningThread();
+ MOZ_ASSERT(aFile);
+
+ aRv = aFile->GetLeafName(aRetval);
+ NS_WARNING_ASSERTION(!aRv.Failed(), "GetLeafName failed");
+}
+
+void
+FileSystemBase::GetDOMPath(nsIFile* aFile,
+ nsAString& aRetval,
+ ErrorResult& aRv) const
+{
+ AssertIsOnOwningThread();
+ MOZ_ASSERT(aFile);
+
+ aRetval.Truncate();
+
+ nsCOMPtr<nsIFile> fileSystemPath;
+ aRv = NS_NewLocalFile(LocalRootPath(), true, getter_AddRefs(fileSystemPath));
+ 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) {
+ nsAutoString leafName;
+ aRv = path->GetLeafName(leafName);
+ if (NS_WARN_IF(aRv.Failed())) {
+ return;
+ }
+
+ if (!leafName.IsEmpty()) {
+ parts.AppendElement(leafName);
+ }
+
+ bool equal = false;
+ aRv = fileSystemPath->Equals(path, &equal);
+ if (NS_WARN_IF(aRv.Failed())) {
+ return;
+ }
+
+ if (equal) {
+ break;
+ }
+
+ 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;
+ }
+ }
+
+ if (parts.IsEmpty()) {
+ aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
+ return;
+ }
+
+ for (int32_t i = parts.Length() - 1; i >= 0; --i) {
+ aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
+ aRetval.Append(parts[i]);
+ }
+}
+
+void
+FileSystemBase::AssertIsOnOwningThread() const
+{
+ MOZ_ASSERT(mOwningThread);
+ MOZ_ASSERT(PR_GetCurrentThread() == mOwningThread);
+}
+
+} // namespace dom
+} // namespace mozilla