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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_idbfilerequest_h__
8 #define mozilla_dom_idbfilerequest_h__
10 #include "DOMRequest.h"
11 #include "js/TypeDecls.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/dom/ScriptSettings.h"
14 #include "nsCycleCollectionParticipant.h"
19 class EventChainPreVisitor
;
25 class IDBFileRequest final
: public DOMRequest
{
26 RefPtr
<IDBFileHandle
> mFileHandle
;
30 bool mWrapAsDOMRequest
;
34 [[nodiscard
]] static RefPtr
<IDBFileRequest
> Create(IDBFileHandle
* aFileHandle
,
35 bool aWrapAsDOMRequest
);
37 void SetEncoding(const nsAString
& aEncoding
) {
38 mEncoding
= aEncoding
;
42 const nsAString
& GetEncoding() const { return mEncoding
; }
44 bool HasEncoding() const { return mHasEncoding
; }
46 void FireProgressEvent(uint64_t aLoaded
, uint64_t aTotal
);
48 template <typename ResultCallback
>
49 void SetResult(const ResultCallback
& aCallback
) {
50 AssertIsOnOwningThread();
53 if (NS_WARN_IF(!autoJS
.Init(GetOwnerGlobal()))) {
54 FireError(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR
);
58 JSContext
* cx
= autoJS
.cx();
60 JS::Rooted
<JS::Value
> result(cx
);
61 nsresult rv
= aCallback(cx
, &result
);
62 if (NS_WARN_IF(NS_FAILED(rv
))) {
70 IDBFileHandle
* GetFileHandle() const {
71 AssertIsOnOwningThread();
75 IDBFileHandle
* GetLockedFile() const {
76 AssertIsOnOwningThread();
77 return GetFileHandle();
80 IMPL_EVENT_HANDLER(progress
)
82 void AssertIsOnOwningThread() const {
83 NS_ASSERT_OWNINGTHREAD(IDBFileRequest
);
86 NS_DECL_ISUPPORTS_INHERITED
87 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBFileRequest
, DOMRequest
)
90 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
93 virtual JSObject
* WrapObject(JSContext
* aCx
,
94 JS::Handle
<JSObject
*> aGivenProto
) override
;
97 IDBFileRequest(IDBFileHandle
* aFileHandle
, bool aWrapAsDOMRequest
);
103 } // namespace mozilla
105 #endif // mozilla_dom_idbfilerequest_h__