Backed out 3 changesets (bug 1876811) for causing bp-nu bustages in nsGfxScrollFrame...
[gecko.git] / dom / filesystem / FileSystemBase.cpp
blob776ecc9db5294e6ccd519c1b48990fffb1919369
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/. */
7 #include "mozilla/dom/FileSystemBase.h"
9 #include "mozilla/ErrorResult.h"
10 #include "mozilla/dom/BlobImpl.h"
11 #include "mozilla/dom/FileSystemUtils.h"
12 #include "nsIFile.h"
13 #include "OSFileSystem.h"
15 namespace mozilla::dom {
17 FileSystemBase::FileSystemBase() : mShutdown(false) {}
19 FileSystemBase::~FileSystemBase() { AssertIsOnOwningThread(); }
21 void FileSystemBase::Shutdown() {
22 AssertIsOnOwningThread();
23 mShutdown = true;
26 nsIGlobalObject* FileSystemBase::GetParentObject() const {
27 AssertIsOnOwningThread();
28 return nullptr;
31 bool FileSystemBase::GetRealPath(BlobImpl* aFile, nsIFile** aPath) const {
32 AssertIsOnOwningThread();
33 MOZ_ASSERT(aFile, "aFile Should not be null.");
34 MOZ_ASSERT(aPath);
36 nsAutoString filePath;
37 ErrorResult rv;
38 aFile->GetMozFullPathInternal(filePath, rv);
39 if (NS_WARN_IF(rv.Failed())) {
40 rv.SuppressException();
41 return false;
44 rv = NS_NewLocalFile(filePath, true, aPath);
45 if (NS_WARN_IF(rv.Failed())) {
46 rv.SuppressException();
47 return false;
50 return true;
53 bool FileSystemBase::IsSafeFile(nsIFile* aFile) const {
54 AssertIsOnOwningThread();
55 return false;
58 bool FileSystemBase::IsSafeDirectory(Directory* aDir) const {
59 AssertIsOnOwningThread();
60 return false;
63 void FileSystemBase::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
64 ErrorResult& aRv) const {
65 AssertIsOnOwningThread();
66 MOZ_ASSERT(aFile);
68 aRv = aFile->GetLeafName(aRetval);
69 NS_WARNING_ASSERTION(!aRv.Failed(), "GetLeafName failed");
72 void FileSystemBase::GetDOMPath(nsIFile* aFile, nsAString& aRetval,
73 ErrorResult& aRv) const {
74 AssertIsOnOwningThread();
75 MOZ_ASSERT(aFile);
77 aRetval.Truncate();
79 nsCOMPtr<nsIFile> fileSystemPath;
80 aRv = NS_NewLocalFile(LocalRootPath(), true, getter_AddRefs(fileSystemPath));
81 if (NS_WARN_IF(aRv.Failed())) {
82 return;
85 nsCOMPtr<nsIFile> path;
86 aRv = aFile->Clone(getter_AddRefs(path));
87 if (NS_WARN_IF(aRv.Failed())) {
88 return;
91 nsTArray<nsString> parts;
93 while (true) {
94 nsAutoString leafName;
95 aRv = path->GetLeafName(leafName);
96 if (NS_WARN_IF(aRv.Failed())) {
97 return;
100 if (!leafName.IsEmpty()) {
101 parts.AppendElement(leafName);
104 bool equal = false;
105 aRv = fileSystemPath->Equals(path, &equal);
106 if (NS_WARN_IF(aRv.Failed())) {
107 return;
110 if (equal) {
111 break;
114 nsCOMPtr<nsIFile> parentPath;
115 aRv = path->GetParent(getter_AddRefs(parentPath));
116 if (NS_WARN_IF(aRv.Failed())) {
117 return;
120 MOZ_ASSERT(parentPath);
122 aRv = parentPath->Clone(getter_AddRefs(path));
123 if (NS_WARN_IF(aRv.Failed())) {
124 return;
128 if (parts.IsEmpty()) {
129 aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
130 return;
133 for (int32_t i = parts.Length() - 1; i >= 0; --i) {
134 aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
135 aRetval.Append(parts[i]);
139 void FileSystemBase::AssertIsOnOwningThread() const {
140 NS_ASSERT_OWNINGTHREAD(FileSystemBase);
143 } // namespace mozilla::dom