Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/filesystem/FileSystemBase.cpp
Line
Count
Source (jump to first uncovered line)
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/FileSystemBase.h"
8
9
#include "nsCharSeparatedTokenizer.h"
10
#include "OSFileSystem.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
FileSystemBase::FileSystemBase()
16
  : mShutdown(false)
17
0
{
18
0
}
19
20
FileSystemBase::~FileSystemBase()
21
0
{
22
0
  AssertIsOnOwningThread();
23
0
}
24
25
void
26
FileSystemBase::Shutdown()
27
0
{
28
0
  AssertIsOnOwningThread();
29
0
  mShutdown = true;
30
0
}
31
32
nsISupports*
33
FileSystemBase::GetParentObject() const
34
0
{
35
0
  AssertIsOnOwningThread();
36
0
  return nullptr;
37
0
}
38
39
bool
40
FileSystemBase::GetRealPath(BlobImpl* aFile, nsIFile** aPath) const
41
0
{
42
0
  AssertIsOnOwningThread();
43
0
  MOZ_ASSERT(aFile, "aFile Should not be null.");
44
0
  MOZ_ASSERT(aPath);
45
0
46
0
  nsAutoString filePath;
47
0
  ErrorResult rv;
48
0
  aFile->GetMozFullPathInternal(filePath, rv);
49
0
  if (NS_WARN_IF(rv.Failed())) {
50
0
    rv.SuppressException();
51
0
    return false;
52
0
  }
53
0
54
0
  rv = NS_NewLocalFile(filePath, true, aPath);
55
0
  if (NS_WARN_IF(rv.Failed())) {
56
0
    rv.SuppressException();
57
0
    return false;
58
0
  }
59
0
60
0
  return true;
61
0
}
62
63
bool
64
FileSystemBase::IsSafeFile(nsIFile* aFile) const
65
0
{
66
0
  AssertIsOnOwningThread();
67
0
  return false;
68
0
}
69
70
bool
71
FileSystemBase::IsSafeDirectory(Directory* aDir) const
72
0
{
73
0
  AssertIsOnOwningThread();
74
0
  return false;
75
0
}
76
77
void
78
FileSystemBase::GetDirectoryName(nsIFile* aFile, nsAString& aRetval,
79
                                 ErrorResult& aRv) const
80
0
{
81
0
  AssertIsOnOwningThread();
82
0
  MOZ_ASSERT(aFile);
83
0
84
0
  aRv = aFile->GetLeafName(aRetval);
85
0
  NS_WARNING_ASSERTION(!aRv.Failed(), "GetLeafName failed");
86
0
}
87
88
void
89
FileSystemBase::GetDOMPath(nsIFile* aFile,
90
                           nsAString& aRetval,
91
                           ErrorResult& aRv) const
92
0
{
93
0
  AssertIsOnOwningThread();
94
0
  MOZ_ASSERT(aFile);
95
0
96
0
  aRetval.Truncate();
97
0
98
0
  nsCOMPtr<nsIFile> fileSystemPath;
99
0
  aRv = NS_NewLocalFile(LocalRootPath(), true, getter_AddRefs(fileSystemPath));
100
0
  if (NS_WARN_IF(aRv.Failed())) {
101
0
    return;
102
0
  }
103
0
104
0
  nsCOMPtr<nsIFile> path;
105
0
  aRv = aFile->Clone(getter_AddRefs(path));
106
0
  if (NS_WARN_IF(aRv.Failed())) {
107
0
    return;
108
0
  }
109
0
110
0
  nsTArray<nsString> parts;
111
0
112
0
  while (true) {
113
0
    nsAutoString leafName;
114
0
    aRv = path->GetLeafName(leafName);
115
0
    if (NS_WARN_IF(aRv.Failed())) {
116
0
      return;
117
0
    }
118
0
119
0
    if (!leafName.IsEmpty()) {
120
0
      parts.AppendElement(leafName);
121
0
    }
122
0
123
0
    bool equal = false;
124
0
    aRv = fileSystemPath->Equals(path, &equal);
125
0
    if (NS_WARN_IF(aRv.Failed())) {
126
0
      return;
127
0
    }
128
0
129
0
    if (equal) {
130
0
      break;
131
0
    }
132
0
133
0
    nsCOMPtr<nsIFile> parentPath;
134
0
    aRv = path->GetParent(getter_AddRefs(parentPath));
135
0
    if (NS_WARN_IF(aRv.Failed())) {
136
0
      return;
137
0
    }
138
0
139
0
    MOZ_ASSERT(parentPath);
140
0
141
0
    aRv = parentPath->Clone(getter_AddRefs(path));
142
0
    if (NS_WARN_IF(aRv.Failed())) {
143
0
      return;
144
0
    }
145
0
  }
146
0
147
0
  if (parts.IsEmpty()) {
148
0
    aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
149
0
    return;
150
0
  }
151
0
152
0
  for (int32_t i = parts.Length() - 1; i >= 0; --i) {
153
0
    aRetval.AppendLiteral(FILESYSTEM_DOM_PATH_SEPARATOR_LITERAL);
154
0
    aRetval.Append(parts[i]);
155
0
  }
156
0
}
157
158
void
159
FileSystemBase::AssertIsOnOwningThread() const
160
0
{
161
0
  NS_ASSERT_OWNINGTHREAD(FileSystemBase);
162
0
}
163
164
} // namespace dom
165
} // namespace mozilla