Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/file/BaseBlobImpl.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
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/dom/BaseBlobImpl.h"
8
#include "nsRFPService.h"
9
#include "prtime.h"
10
11
namespace mozilla {
12
namespace dom {
13
14
void
15
BaseBlobImpl::GetName(nsAString& aName) const
16
0
{
17
0
  MOZ_ASSERT(mIsFile, "Should only be called on files");
18
0
  aName = mName;
19
0
}
20
21
void
22
BaseBlobImpl::GetDOMPath(nsAString& aPath) const
23
0
{
24
0
  MOZ_ASSERT(mIsFile, "Should only be called on files");
25
0
  aPath = mPath;
26
0
}
27
28
void
29
BaseBlobImpl::SetDOMPath(const nsAString& aPath)
30
0
{
31
0
  MOZ_ASSERT(mIsFile, "Should only be called on files");
32
0
  mPath = aPath;
33
0
}
34
35
void
36
BaseBlobImpl::GetMozFullPath(nsAString& aFileName,
37
                             SystemCallerGuarantee /* unused */,
38
                             ErrorResult& aRv) const
39
0
{
40
0
  MOZ_ASSERT(mIsFile, "Should only be called on files");
41
0
42
0
  GetMozFullPathInternal(aFileName, aRv);
43
0
}
44
45
void
46
BaseBlobImpl::GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv) const
47
0
{
48
0
  if (!mIsFile) {
49
0
    aRv.Throw(NS_ERROR_FAILURE);
50
0
    return;
51
0
  }
52
0
53
0
  aFileName.Truncate();
54
0
}
55
56
void
57
BaseBlobImpl::GetType(nsAString& aType)
58
0
{
59
0
  aType = mContentType;
60
0
}
61
62
int64_t
63
BaseBlobImpl::GetLastModified(ErrorResult& aRv)
64
0
{
65
0
  MOZ_ASSERT(mIsFile, "Should only be called on files");
66
0
  if (IsDateUnknown()) {
67
0
    mLastModificationDate = nsRFPService::ReduceTimePrecisionAsUSecs(PR_Now(), 0);
68
0
    // mLastModificationDate is an absolute timestamp so we supply a zero context mix-in
69
0
  }
70
0
71
0
  return mLastModificationDate / PR_USEC_PER_MSEC;
72
0
}
73
74
void
75
BaseBlobImpl::SetLastModified(int64_t aLastModified)
76
0
{
77
0
  mLastModificationDate = aLastModified * PR_USEC_PER_MSEC;
78
0
}
79
80
int64_t
81
BaseBlobImpl::GetFileId()
82
0
{
83
0
  return -1;
84
0
}
85
86
nsresult
87
BaseBlobImpl::GetSendInfo(nsIInputStream** aBody, uint64_t* aContentLength,
88
                          nsACString& aContentType, nsACString& aCharset)
89
0
{
90
0
  MOZ_ASSERT(aContentLength);
91
0
92
0
  ErrorResult rv;
93
0
94
0
  nsCOMPtr<nsIInputStream> stream;
95
0
  CreateInputStream(getter_AddRefs(stream), rv);
96
0
  if (NS_WARN_IF(rv.Failed())) {
97
0
    return rv.StealNSResult();
98
0
  }
99
0
100
0
  *aContentLength = GetSize(rv);
101
0
  if (NS_WARN_IF(rv.Failed())) {
102
0
    return rv.StealNSResult();
103
0
  }
104
0
105
0
  nsAutoString contentType;
106
0
  GetType(contentType);
107
0
108
0
  if (contentType.IsEmpty()) {
109
0
    aContentType.SetIsVoid(true);
110
0
  } else {
111
0
    CopyUTF16toUTF8(contentType, aContentType);
112
0
  }
113
0
114
0
  aCharset.Truncate();
115
0
116
0
  stream.forget(aBody);
117
0
  return NS_OK;
118
0
}
119
120
nsresult
121
BaseBlobImpl::GetMutable(bool* aMutable) const
122
0
{
123
0
  *aMutable = !mImmutable;
124
0
  return NS_OK;
125
0
}
126
127
nsresult
128
BaseBlobImpl::SetMutable(bool aMutable)
129
0
{
130
0
  nsresult rv = NS_OK;
131
0
132
0
  NS_ENSURE_ARG(!mImmutable || !aMutable);
133
0
134
0
  if (!mImmutable && !aMutable) {
135
0
    // Force the content type and size to be cached
136
0
    nsAutoString dummyString;
137
0
    GetType(dummyString);
138
0
139
0
    ErrorResult error;
140
0
    GetSize(error);
141
0
    if (NS_WARN_IF(error.Failed())) {
142
0
      return error.StealNSResult();
143
0
    }
144
0
  }
145
0
146
0
  mImmutable = !aMutable;
147
0
  return rv;
148
0
}
149
150
/* static */ uint64_t
151
BaseBlobImpl::NextSerialNumber()
152
0
{
153
0
  static Atomic<uint64_t> nextSerialNumber;
154
0
  return nextSerialNumber++;
155
0
}
156
157
} // namespace dom
158
} // namespace mozilla