2012-06-03 09:33:52 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 12:32:37 -07:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-06-03 09:33:52 -07: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/. */
|
|
|
|
|
2014-06-11 20:35:29 -07:00
|
|
|
#include "IDBMutableFile.h"
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "FileSnapshot.h"
|
|
|
|
#include "FileInfo.h"
|
|
|
|
#include "IDBDatabase.h"
|
|
|
|
#include "IDBFactory.h"
|
|
|
|
#include "IDBFileHandle.h"
|
|
|
|
#include "IDBFileRequest.h"
|
|
|
|
#include "IndexedDatabaseManager.h"
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
2014-07-17 09:40:54 -07:00
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/dom/FileService.h"
|
2014-06-11 20:35:29 -07:00
|
|
|
#include "mozilla/dom/IDBMutableFileBinding.h"
|
2014-07-17 09:40:54 -07:00
|
|
|
#include "mozilla/dom/MetadataHelper.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
|
2012-12-17 11:25:10 -08:00
|
|
|
#include "mozilla/dom/quota/FileStreams.h"
|
2014-05-07 07:33:02 -07:00
|
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
|
|
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
2014-07-17 09:40:54 -07:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsError.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "nsIPrincipal.h"
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace indexedDB {
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
using namespace mozilla::dom::quota;
|
|
|
|
using namespace mozilla::ipc;
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-07-17 09:40:54 -07:00
|
|
|
class GetFileHelper : public MetadataHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GetFileHelper(FileHandleBase* aFileHandle,
|
|
|
|
FileRequestBase* aFileRequest,
|
|
|
|
MetadataParameters* aParams,
|
|
|
|
IDBMutableFile* aMutableFile)
|
|
|
|
: MetadataHelper(aFileHandle, aFileRequest, aParams),
|
|
|
|
mMutableFile(aMutableFile)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
GetSuccessResult(JSContext* aCx,
|
2015-03-21 09:28:04 -07:00
|
|
|
JS::MutableHandle<JS::Value> aVal) override;
|
2014-07-17 09:40:54 -07:00
|
|
|
|
|
|
|
virtual void
|
2015-03-21 09:28:04 -07:00
|
|
|
ReleaseObjects() override
|
2014-07-17 09:40:54 -07:00
|
|
|
{
|
|
|
|
mMutableFile = nullptr;
|
|
|
|
MetadataHelper::ReleaseObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsRefPtr<IDBMutableFile> mMutableFile;
|
|
|
|
};
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
already_AddRefed<nsIFile>
|
|
|
|
GetFileFor(FileInfo* aFileInfo)
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aFileInfo);
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
FileManager* fileManager = aFileInfo->Manager();
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(fileManager);
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
nsCOMPtr<nsIFile> directory = fileManager->GetDirectory();
|
2014-09-26 16:21:57 -07:00
|
|
|
if (NS_WARN_IF(!directory)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsCOMPtr<nsIFile> file =
|
|
|
|
fileManager->GetFileForId(directory, aFileInfo->Id());
|
|
|
|
if (NS_WARN_IF(!file)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
return file.forget();
|
|
|
|
}
|
|
|
|
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBMutableFile::IDBMutableFile(IDBDatabase* aDatabase,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aType,
|
|
|
|
already_AddRefed<FileInfo> aFileInfo,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin,
|
|
|
|
const nsACString& aStorageId,
|
|
|
|
PersistenceType aPersistenceType,
|
|
|
|
already_AddRefed<nsIFile> aFile)
|
|
|
|
: DOMEventTargetHelper(aDatabase)
|
|
|
|
, mDatabase(aDatabase)
|
|
|
|
, mFileInfo(aFileInfo)
|
|
|
|
, mGroup(aGroup)
|
|
|
|
, mOrigin(aOrigin)
|
|
|
|
, mPersistenceType(aPersistenceType)
|
|
|
|
, mInvalidated(false)
|
2014-09-17 16:36:01 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mDatabase);
|
|
|
|
MOZ_ASSERT(mFileInfo);
|
|
|
|
|
|
|
|
mName = aName;
|
|
|
|
mType = aType;
|
|
|
|
mFile = aFile;
|
|
|
|
mStorageId = aStorageId;
|
|
|
|
mFileName.AppendInt(mFileInfo->Id());
|
|
|
|
|
|
|
|
MOZ_ASSERT(mFile);
|
|
|
|
|
|
|
|
mDatabase->NoteLiveMutableFile(this);
|
2014-01-06 18:53:23 -08:00
|
|
|
}
|
|
|
|
|
2014-07-17 09:40:54 -07:00
|
|
|
IDBMutableFile::~IDBMutableFile()
|
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
// XXX This is always in the main process but it sometimes happens too late in
|
|
|
|
// shutdown and the IndexedDatabaseManager has already been torn down.
|
|
|
|
// MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
if (mDatabase) {
|
|
|
|
mDatabase->NoteFinishedMutableFile(this);
|
|
|
|
}
|
|
|
|
}
|
2014-09-17 16:36:01 -07:00
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
// static
|
2014-06-11 20:35:29 -07:00
|
|
|
already_AddRefed<IDBMutableFile>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBMutableFile::Create(IDBDatabase* aDatabase,
|
|
|
|
const nsAString& aName,
|
2014-06-11 20:35:29 -07:00
|
|
|
const nsAString& aType,
|
|
|
|
already_AddRefed<FileInfo> aFileInfo)
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
nsRefPtr<FileInfo> fileInfo(aFileInfo);
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(fileInfo);
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
PrincipalInfo* principalInfo = aDatabase->Factory()->GetPrincipalInfo();
|
|
|
|
MOZ_ASSERT(principalInfo);
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(*principalInfo);
|
|
|
|
if (NS_WARN_IF(!principal)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsCString group;
|
|
|
|
nsCString origin;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(QuotaManager::GetInfoFromPrincipal(principal,
|
|
|
|
&group,
|
|
|
|
&origin,
|
|
|
|
nullptr)))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-05-07 07:33:02 -07:00
|
|
|
|
2014-11-28 00:44:12 -08:00
|
|
|
const DatabaseSpec* spec = aDatabase->Spec();
|
|
|
|
MOZ_ASSERT(spec);
|
|
|
|
|
2015-06-30 05:59:27 -07:00
|
|
|
const DatabaseMetadata& metadata = spec->metadata();
|
|
|
|
|
|
|
|
PersistenceType persistenceType = metadata.persistenceType();
|
2014-11-28 00:44:12 -08:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsCString storageId;
|
|
|
|
QuotaManager::GetStorageId(persistenceType,
|
|
|
|
origin,
|
|
|
|
Client::IDB,
|
|
|
|
storageId);
|
|
|
|
|
2015-06-30 05:59:27 -07:00
|
|
|
storageId.Append('*');
|
|
|
|
storageId.Append(NS_ConvertUTF16toUTF8(metadata.name()));
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsCOMPtr<nsIFile> file = GetFileFor(fileInfo);
|
|
|
|
if (NS_WARN_IF(!file)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDBMutableFile> newFile =
|
|
|
|
new IDBMutableFile(aDatabase,
|
|
|
|
aName,
|
|
|
|
aType,
|
|
|
|
fileInfo.forget(),
|
|
|
|
group,
|
|
|
|
origin,
|
|
|
|
storageId,
|
|
|
|
persistenceType,
|
|
|
|
file.forget());
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
return newFile.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
void
|
|
|
|
IDBMutableFile::Invalidate()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mInvalidated);
|
|
|
|
|
|
|
|
mInvalidated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBMutableFile, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBMutableFile, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBMutableFile)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBMutableFile)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBMutableFile,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDatabase)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBMutableFile,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
MOZ_ASSERT(tmp->mDatabase);
|
|
|
|
tmp->mDatabase->NoteFinishedMutableFile(tmp);
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDatabase)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2014-05-07 07:33:02 -07:00
|
|
|
bool
|
2014-06-11 20:35:29 -07:00
|
|
|
IDBMutableFile::IsInvalid()
|
2014-05-07 07:33:02 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
return mInvalidated;
|
2014-05-07 07:33:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIOfflineStorage*
|
2014-06-11 20:35:29 -07:00
|
|
|
IDBMutableFile::Storage()
|
2014-05-07 07:33:02 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_CRASH("Don't call me!");
|
2014-05-07 07:33:02 -07:00
|
|
|
}
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
already_AddRefed<nsISupports>
|
2014-07-17 09:40:54 -07:00
|
|
|
IDBMutableFile::CreateStream(bool aReadOnly)
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
|
2012-12-17 11:25:10 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> result;
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
if (aReadOnly) {
|
2013-09-10 21:18:36 -07:00
|
|
|
nsRefPtr<FileInputStream> stream =
|
2014-09-26 16:21:57 -07:00
|
|
|
FileInputStream::Create(mPersistenceType,
|
|
|
|
mGroup,
|
|
|
|
mOrigin,
|
|
|
|
mFile,
|
|
|
|
-1,
|
|
|
|
-1,
|
2013-09-10 21:18:36 -07:00
|
|
|
nsIFileInputStream::DEFER_OPEN);
|
2012-12-17 11:25:10 -08:00
|
|
|
result = NS_ISUPPORTS_CAST(nsIFileInputStream*, stream);
|
2014-09-26 16:21:57 -07:00
|
|
|
} else {
|
2013-09-10 21:18:36 -07:00
|
|
|
nsRefPtr<FileStream> stream =
|
2014-09-26 16:21:57 -07:00
|
|
|
FileStream::Create(mPersistenceType,
|
|
|
|
mGroup,
|
|
|
|
mOrigin,
|
|
|
|
mFile,
|
|
|
|
-1,
|
|
|
|
-1,
|
2013-09-10 21:18:36 -07:00
|
|
|
nsIFileStream::DEFER_OPEN);
|
2012-12-17 11:25:10 -08:00
|
|
|
result = NS_ISUPPORTS_CAST(nsIFileStream*, stream);
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
if (NS_WARN_IF(!result)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
IDBMutableFile::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2012-06-03 09:33:52 -07:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return IDBMutableFileBinding::Wrap(aCx, this, aGivenProto);
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBDatabase*
|
|
|
|
IDBMutableFile::Database() const
|
2014-02-24 12:56:13 -08:00
|
|
|
{
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
return mDatabase;
|
2014-02-24 12:56:13 -08:00
|
|
|
}
|
2014-07-17 09:40:54 -07:00
|
|
|
|
|
|
|
already_AddRefed<IDBFileHandle>
|
|
|
|
IDBMutableFile::Open(FileMode aMode, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (QuotaManager::IsShuttingDown() || FileService::IsShuttingDown()) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-02 13:14:22 -08:00
|
|
|
if (mDatabase->IsClosed()) {
|
2014-11-04 23:30:21 -08:00
|
|
|
aError.Throw(NS_ERROR_DOM_FILEHANDLE_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-02 13:14:22 -08:00
|
|
|
MOZ_ASSERT(GetOwner());
|
|
|
|
|
2014-07-17 09:40:54 -07:00
|
|
|
nsRefPtr<IDBFileHandle> fileHandle =
|
|
|
|
IDBFileHandle::Create(aMode, FileHandleBase::NORMAL, this);
|
|
|
|
if (!fileHandle) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fileHandle.forget();
|
|
|
|
}
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
int64_t
|
|
|
|
IDBMutableFile::GetFileId() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mFileInfo);
|
|
|
|
|
|
|
|
return mFileInfo->Id();
|
|
|
|
}
|
|
|
|
|
2015-05-18 06:52:26 -07:00
|
|
|
already_AddRefed<File>
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBMutableFile::CreateFileObject(IDBFileHandle* aFileHandle,
|
|
|
|
MetadataParameters* aMetadataParams)
|
|
|
|
{
|
2015-05-12 05:11:03 -07:00
|
|
|
nsRefPtr<BlobImpl> impl =
|
|
|
|
new BlobImplSnapshot(mName,
|
2014-09-26 16:21:57 -07:00
|
|
|
mType,
|
|
|
|
aMetadataParams,
|
|
|
|
mFile,
|
|
|
|
aFileHandle,
|
|
|
|
mFileInfo);
|
|
|
|
|
2015-05-12 05:09:51 -07:00
|
|
|
nsRefPtr<File> file = File::Create(GetOwner(), impl);
|
|
|
|
MOZ_ASSERT(file);
|
|
|
|
|
|
|
|
return file.forget();
|
2014-09-26 16:21:57 -07:00
|
|
|
}
|
|
|
|
|
2014-07-17 09:40:54 -07:00
|
|
|
already_AddRefed<DOMRequest>
|
|
|
|
IDBMutableFile::GetFile(ErrorResult& aError)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-03-02 13:14:22 -08:00
|
|
|
if (QuotaManager::IsShuttingDown() || FileService::IsShuttingDown()) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDatabase->IsClosed()) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_FILEHANDLE_NOT_ALLOWED_ERR);
|
2014-07-17 09:40:54 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-03-02 13:14:22 -08:00
|
|
|
MOZ_ASSERT(GetOwner());
|
|
|
|
|
2014-07-17 09:40:54 -07:00
|
|
|
nsRefPtr<IDBFileHandle> fileHandle =
|
|
|
|
IDBFileHandle::Create(FileMode::Readonly, FileHandleBase::PARALLEL, this);
|
|
|
|
|
|
|
|
nsRefPtr<IDBFileRequest> request =
|
2014-09-26 16:21:57 -07:00
|
|
|
IDBFileRequest::Create(GetOwner(),
|
|
|
|
fileHandle,
|
|
|
|
/* aWrapAsDOMRequest */ true);
|
2014-07-17 09:40:54 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
nsRefPtr<MetadataParameters> params = new MetadataParameters(true, true);
|
2014-07-17 09:40:54 -07:00
|
|
|
|
|
|
|
nsRefPtr<GetFileHelper> helper =
|
|
|
|
new GetFileHelper(fileHandle, request, params, this);
|
|
|
|
|
|
|
|
nsresult rv = helper->Enqueue();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return request.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetFileHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aVal)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
auto fileHandle = static_cast<IDBFileHandle*>(mFileHandle.get());
|
|
|
|
|
2015-05-18 06:52:26 -07:00
|
|
|
nsRefPtr<File> domFile =
|
2014-09-26 16:21:57 -07:00
|
|
|
mMutableFile->CreateFileObject(fileHandle, mParams);
|
2014-07-17 09:40:54 -07:00
|
|
|
|
2015-05-18 06:52:26 -07:00
|
|
|
if (!ToJSValue(aCx, domFile, aVal)) {
|
2014-07-17 09:40:54 -07:00
|
|
|
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-09-26 16:21:57 -07:00
|
|
|
|
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|