2014-07-17 16:40:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 19:32:37 +00:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-07-17 16:40:54 +00:00
|
|
|
/* 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 "FileSnapshot.h"
|
|
|
|
|
|
|
|
#include "IDBFileHandle.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "MainThreadUtils.h"
|
2014-07-17 16:40:54 +00:00
|
|
|
#include "mozilla/Assertions.h"
|
2015-06-22 23:31:28 +00:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/dom/MetadataHelper.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#endif
|
2014-07-17 16:40:54 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
|
|
|
|
|
|
|
// Create as a stored file
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::BlobImplSnapshot(const nsAString& aName,
|
2014-07-17 16:40:54 +00:00
|
|
|
const nsAString& aContentType,
|
2014-09-26 23:21:57 +00:00
|
|
|
MetadataParameters* aMetadataParams,
|
|
|
|
nsIFile* aFile,
|
2014-07-17 16:40:54 +00:00
|
|
|
IDBFileHandle* aFileHandle,
|
|
|
|
FileInfo* aFileInfo)
|
2015-05-12 12:11:03 +00:00
|
|
|
: BlobImplBase(aName,
|
2014-10-08 16:15:23 +00:00
|
|
|
aContentType,
|
|
|
|
aMetadataParams->Size(),
|
2015-06-22 23:31:40 +00:00
|
|
|
aMetadataParams->LastModified())
|
2014-09-26 23:21:57 +00:00
|
|
|
, mFile(aFile)
|
|
|
|
, mWholeFile(true)
|
2014-07-17 16:40:54 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertSanity();
|
|
|
|
MOZ_ASSERT(aMetadataParams);
|
|
|
|
MOZ_ASSERT(aMetadataParams->Size() != UINT64_MAX);
|
|
|
|
MOZ_ASSERT(aMetadataParams->LastModified() != INT64_MAX);
|
|
|
|
MOZ_ASSERT(aFile);
|
|
|
|
MOZ_ASSERT(aFileHandle);
|
|
|
|
MOZ_ASSERT(aFileInfo);
|
|
|
|
|
2014-07-17 16:40:54 +00:00
|
|
|
mFileInfos.AppendElement(aFileInfo);
|
2015-01-11 21:35:24 +00:00
|
|
|
|
|
|
|
mFileHandle =
|
|
|
|
do_GetWeakReference(NS_ISUPPORTS_CAST(EventTarget*, aFileHandle));
|
2014-07-17 16:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create slice
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::BlobImplSnapshot(const BlobImplSnapshot* aOther,
|
2014-09-26 23:21:57 +00:00
|
|
|
uint64_t aStart,
|
|
|
|
uint64_t aLength,
|
2014-07-17 16:40:54 +00:00
|
|
|
const nsAString& aContentType)
|
2015-05-12 12:11:03 +00:00
|
|
|
: BlobImplBase(aContentType, aOther->mStart + aStart, aLength)
|
2014-09-26 23:21:57 +00:00
|
|
|
, mFile(aOther->mFile)
|
|
|
|
, mFileHandle(aOther->mFileHandle)
|
|
|
|
, mWholeFile(false)
|
2014-07-17 16:40:54 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertSanity();
|
|
|
|
MOZ_ASSERT(aOther);
|
2014-07-17 16:40:54 +00:00
|
|
|
|
|
|
|
FileInfo* fileInfo;
|
|
|
|
|
|
|
|
if (IndexedDatabaseManager::IsClosed()) {
|
|
|
|
fileInfo = aOther->GetFileInfo();
|
|
|
|
} else {
|
|
|
|
MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
|
|
|
|
fileInfo = aOther->GetFileInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
mFileInfos.AppendElement(fileInfo);
|
|
|
|
}
|
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::~BlobImplSnapshot()
|
2014-07-17 16:40:54 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::AssertSanity()
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
2015-07-04 01:29:00 +00:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
2014-09-26 23:21:57 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(BlobImplSnapshot, BlobImpl, PIBlobImplSnapshot)
|
2014-09-26 23:21:57 +00:00
|
|
|
|
2015-05-19 14:36:37 +00:00
|
|
|
void
|
|
|
|
BlobImplSnapshot::GetInternalStream(nsIInputStream** aStream,
|
|
|
|
ErrorResult& aRv)
|
2014-07-17 16:40:54 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertSanity();
|
2014-07-17 16:40:54 +00:00
|
|
|
|
2015-01-11 21:35:24 +00:00
|
|
|
nsCOMPtr<EventTarget> et = do_QueryReferent(mFileHandle);
|
|
|
|
nsRefPtr<IDBFileHandle> fileHandle = static_cast<IDBFileHandle*>(et.get());
|
|
|
|
if (!fileHandle) {
|
2015-05-19 14:36:37 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_FILEHANDLE_INACTIVE_ERR);
|
|
|
|
return;
|
2015-01-11 21:35:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 14:36:37 +00:00
|
|
|
aRv = fileHandle->OpenInputStream(mWholeFile, mStart, mLength, aStream);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
|
|
return;
|
2014-09-26 23:21:57 +00:00
|
|
|
}
|
2014-07-17 16:40:54 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
already_AddRefed<BlobImpl>
|
|
|
|
BlobImplSnapshot::CreateSlice(uint64_t aStart,
|
2014-09-26 23:21:57 +00:00
|
|
|
uint64_t aLength,
|
2014-10-08 16:15:22 +00:00
|
|
|
const nsAString& aContentType,
|
|
|
|
ErrorResult& aRv)
|
2014-07-17 16:40:54 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertSanity();
|
2014-07-17 16:40:54 +00:00
|
|
|
|
2015-05-12 12:11:03 +00:00
|
|
|
nsRefPtr<BlobImpl> impl =
|
|
|
|
new BlobImplSnapshot(this, aStart, aLength, aContentType);
|
2014-07-17 16:40:54 +00:00
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
return impl.forget();
|
2014-07-17 16:40:54 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 16:15:22 +00:00
|
|
|
void
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::GetMozFullPathInternal(nsAString& aFilename,
|
2015-06-03 00:11:16 +00:00
|
|
|
ErrorResult& aRv) const
|
2014-07-17 16:40:54 +00:00
|
|
|
{
|
2014-09-26 23:21:57 +00:00
|
|
|
AssertSanity();
|
|
|
|
MOZ_ASSERT(mIsFile);
|
2014-07-17 16:40:54 +00:00
|
|
|
|
2014-10-08 16:15:22 +00:00
|
|
|
aRv = mFile->GetPath(aFilename);
|
2014-07-17 16:40:54 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
bool
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::IsStoredFile() const
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
AssertSanity();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::IsWholeFile() const
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
AssertSanity();
|
|
|
|
|
|
|
|
return mWholeFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-05-12 12:11:03 +00:00
|
|
|
BlobImplSnapshot::IsSnapshot() const
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
AssertSanity();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:40:54 +00:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|