Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_dom_idbfilerequest_h__
8
#define mozilla_dom_idbfilerequest_h__
9
10
#include "DOMRequest.h"
11
#include "js/TypeDecls.h"
12
#include "mozilla/Attributes.h"
13
#include "nsCycleCollectionParticipant.h"
14
#include "nsString.h"
15
16
template <class>
17
struct already_AddRefed;
18
19
namespace mozilla {
20
21
class EventChainPreVisitor;
22
23
namespace dom {
24
25
class IDBFileHandle;
26
27
class IDBFileRequest final : public DOMRequest {
28
RefPtr<IDBFileHandle> mFileHandle;
29
30
nsString mEncoding;
31
32
bool mWrapAsDOMRequest;
33
bool mHasEncoding;
34
35
public:
36
class ResultCallback;
37
38
static already_AddRefed<IDBFileRequest> Create(IDBFileHandle* aFileHandle,
39
bool aWrapAsDOMRequest);
40
41
void SetEncoding(const nsAString& aEncoding) {
42
mEncoding = aEncoding;
43
mHasEncoding = true;
44
}
45
46
const nsAString& GetEncoding() const { return mEncoding; }
47
48
bool HasEncoding() const { return mHasEncoding; }
49
50
void FireProgressEvent(uint64_t aLoaded, uint64_t aTotal);
51
52
void SetResultCallback(ResultCallback* aCallback);
53
54
// WebIDL
55
IDBFileHandle* GetFileHandle() const {
56
AssertIsOnOwningThread();
57
return mFileHandle;
58
}
59
60
IDBFileHandle* GetLockedFile() const {
61
AssertIsOnOwningThread();
62
return GetFileHandle();
63
}
64
65
IMPL_EVENT_HANDLER(progress)
66
67
void AssertIsOnOwningThread() const {
68
NS_ASSERT_OWNINGTHREAD(IDBFileRequest);
69
}
70
71
NS_DECL_ISUPPORTS_INHERITED
72
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBFileRequest, DOMRequest)
73
74
// EventTarget
75
void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
76
77
// nsWrapperCache
78
virtual JSObject* WrapObject(JSContext* aCx,
79
JS::Handle<JSObject*> aGivenProto) override;
80
81
private:
82
IDBFileRequest(IDBFileHandle* aFileHandle, bool aWrapAsDOMRequest);
83
84
~IDBFileRequest();
85
};
86
87
class NS_NO_VTABLE IDBFileRequest::ResultCallback {
88
public:
89
virtual nsresult GetResult(JSContext* aCx,
90
JS::MutableHandle<JS::Value> aResult) = 0;
91
92
protected:
93
ResultCallback() = default;
94
};
95
96
} // namespace dom
97
} // namespace mozilla
98
99
#endif // mozilla_dom_idbfilerequest_h__