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 
GetName(nsAString & aName) const14 void BaseBlobImpl::GetName(nsAString& aName) const {
15   MOZ_ASSERT(mIsFile, "Should only be called on files");
16   aName = mName;
17 }
18 
GetDOMPath(nsAString & aPath) const19 void BaseBlobImpl::GetDOMPath(nsAString& aPath) const {
20   MOZ_ASSERT(mIsFile, "Should only be called on files");
21   aPath = mPath;
22 }
23 
SetDOMPath(const nsAString & aPath)24 void BaseBlobImpl::SetDOMPath(const nsAString& aPath) {
25   MOZ_ASSERT(mIsFile, "Should only be called on files");
26   mPath = aPath;
27 }
28 
GetMozFullPath(nsAString & aFileName,SystemCallerGuarantee,ErrorResult & aRv)29 void BaseBlobImpl::GetMozFullPath(nsAString& aFileName,
30                                   SystemCallerGuarantee /* unused */,
31                                   ErrorResult& aRv) {
32   MOZ_ASSERT(mIsFile, "Should only be called on files");
33 
34   GetMozFullPathInternal(aFileName, aRv);
35 }
36 
GetMozFullPathInternal(nsAString & aFileName,ErrorResult & aRv)37 void BaseBlobImpl::GetMozFullPathInternal(nsAString& aFileName,
38                                           ErrorResult& aRv) {
39   if (!mIsFile) {
40     aRv.Throw(NS_ERROR_FAILURE);
41     return;
42   }
43 
44   aFileName.Truncate();
45 }
46 
GetType(nsAString & aType)47 void BaseBlobImpl::GetType(nsAString& aType) { aType = mContentType; }
48 
GetLastModified(ErrorResult & aRv)49 int64_t BaseBlobImpl::GetLastModified(ErrorResult& aRv) {
50   MOZ_ASSERT(mIsFile, "Should only be called on files");
51   return mLastModificationDate / PR_USEC_PER_MSEC;
52 }
53 
GetFileId()54 int64_t BaseBlobImpl::GetFileId() { return -1; }
55 
56 /* static */
NextSerialNumber()57 uint64_t BaseBlobImpl::NextSerialNumber() {
58   static Atomic<uint64_t> nextSerialNumber;
59   return nextSerialNumber++;
60 }
61 
SetLastModificationDatePrecisely(int64_t aDate)62 void BaseBlobImpl::SetLastModificationDatePrecisely(int64_t aDate) {
63   MOZ_ASSERT(mIsFile, "Should only be called on files");
64   mLastModificationDate = aDate;
65 }
66 
SetLastModificationDate(bool aCrossOriginIsolated,int64_t aDate)67 void BaseBlobImpl::SetLastModificationDate(bool aCrossOriginIsolated,
68                                            int64_t aDate) {
69   return SetLastModificationDatePrecisely(
70       nsRFPService::ReduceTimePrecisionAsUSecs(aDate, 0,
71                                                /* aIsSystemPrincipal */ false,
72                                                aCrossOriginIsolated));
73   // mLastModificationDate is an absolute timestamp so we supply a zero
74   // context mix-in
75 }
76 
77 }  // namespace dom
78 }  // namespace mozilla
79