2014-07-17 20:40:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-07-17 20:40:54 +04: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/. */
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#ifndef mozilla_dom_idbfilehandle_h__
|
|
|
|
#define mozilla_dom_idbfilehandle_h__
|
2014-07-17 20:40:54 +04:00
|
|
|
|
|
|
|
#include "IDBFileRequest.h"
|
|
|
|
#include "js/TypeDecls.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
2015-09-09 14:15:05 +03:00
|
|
|
#include "mozilla/dom/FileHandleBase.h"
|
2014-07-17 20:40:54 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2015-09-09 14:15:05 +03:00
|
|
|
#include "nsIRunnable.h"
|
2015-01-12 00:35:24 +03:00
|
|
|
#include "nsWeakReference.h"
|
2014-07-17 20:40:54 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2014-07-17 20:40:54 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct IDBFileMetadataParameters;
|
2015-09-09 14:15:05 +03:00
|
|
|
class IDBFileRequest;
|
2014-07-17 20:40:54 +04:00
|
|
|
class IDBMutableFile;
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
class IDBFileHandle final
|
|
|
|
: public DOMEventTargetHelper
|
|
|
|
, public nsIRunnable
|
|
|
|
, public FileHandleBase
|
|
|
|
, public nsSupportsWeakReference
|
2014-07-17 20:40:54 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBMutableFile> mMutableFile;
|
2014-07-17 20:40:54 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
public:
|
2014-07-17 20:40:54 +04:00
|
|
|
static already_AddRefed<IDBFileHandle>
|
2015-09-09 14:15:05 +03:00
|
|
|
Create(IDBMutableFile* aMutableFile,
|
|
|
|
FileMode aMode);
|
2014-07-17 20:40:54 +04:00
|
|
|
|
|
|
|
// WebIDL
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2014-07-17 20:40:54 +04:00
|
|
|
GetParentObject() const
|
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBMutableFile*
|
|
|
|
GetMutableFile() const
|
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
return mMutableFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
IDBMutableFile*
|
|
|
|
GetFileHandle() const
|
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
return GetMutableFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBFileRequest>
|
|
|
|
GetMetadata(const IDBFileMetadataParameters& aParameters, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBFileRequest>
|
|
|
|
ReadAsArrayBuffer(uint64_t aSize, ErrorResult& aRv)
|
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
return Read(aSize, false, NullString(), aRv).downcast<IDBFileRequest>();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBFileRequest>
|
|
|
|
ReadAsText(uint64_t aSize, const nsAString& aEncoding, ErrorResult& aRv)
|
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
return Read(aSize, true, aEncoding, aRv).downcast<IDBFileRequest>();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBFileRequest>
|
2015-09-09 14:15:05 +03:00
|
|
|
Write(const StringOrArrayBufferOrArrayBufferViewOrBlob& aValue,
|
|
|
|
ErrorResult& aRv)
|
2014-07-17 20:40:54 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return WriteOrAppend(aValue, false, aRv).downcast<IDBFileRequest>();
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBFileRequest>
|
2015-09-09 14:15:05 +03:00
|
|
|
Append(const StringOrArrayBufferOrArrayBufferViewOrBlob& aValue,
|
|
|
|
ErrorResult& aRv)
|
2014-07-17 20:40:54 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return WriteOrAppend(aValue, true, aRv).downcast<IDBFileRequest>();
|
2014-07-17 20:40:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBFileRequest>
|
|
|
|
Truncate(const Optional<uint64_t>& aSize, ErrorResult& aRv)
|
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
return FileHandleBase::Truncate(aSize, aRv).downcast<IDBFileRequest>();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<IDBFileRequest>
|
|
|
|
Flush(ErrorResult& aRv)
|
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-07-17 20:40:54 +04:00
|
|
|
return FileHandleBase::Flush(aRv).downcast<IDBFileRequest>();
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBFileHandle, DOMEventTargetHelper)
|
|
|
|
|
|
|
|
// nsIDOMEventTarget
|
|
|
|
virtual nsresult
|
|
|
|
PreHandleEvent(EventChainPreVisitor& aVisitor) override;
|
|
|
|
|
|
|
|
// WrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
// FileHandleBase
|
|
|
|
virtual MutableFileBase*
|
|
|
|
MutableFile() const override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
HandleCompleteOrAbort(bool aAborted) override;
|
|
|
|
|
2014-07-17 20:40:54 +04:00
|
|
|
private:
|
|
|
|
IDBFileHandle(FileMode aMode,
|
|
|
|
IDBMutableFile* aMutableFile);
|
|
|
|
~IDBFileHandle();
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
// FileHandleBase
|
2014-07-17 20:40:54 +04:00
|
|
|
virtual bool
|
2015-03-21 19:28:04 +03:00
|
|
|
CheckWindow() override;
|
2014-07-17 20:40:54 +04:00
|
|
|
|
|
|
|
virtual already_AddRefed<FileRequestBase>
|
2015-03-21 19:28:04 +03:00
|
|
|
GenerateFileRequest() override;
|
2014-07-17 20:40:54 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#endif // mozilla_dom_idbfilehandle_h__
|