Line data Source code
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> struct already_AddRefed;
17 :
18 : namespace mozilla {
19 :
20 : class EventChainPreVisitor;
21 :
22 : namespace dom {
23 :
24 : class IDBFileHandle;
25 :
26 : class IDBFileRequest final
27 : : public DOMRequest
28 : {
29 : RefPtr<IDBFileHandle> mFileHandle;
30 :
31 : nsString mEncoding;
32 :
33 : bool mWrapAsDOMRequest;
34 : bool mHasEncoding;
35 :
36 : public:
37 : class ResultCallback;
38 :
39 : static already_AddRefed<IDBFileRequest>
40 : Create(IDBFileHandle* aFileHandle,
41 : bool aWrapAsDOMRequest);
42 :
43 : void
44 0 : SetEncoding(const nsAString& aEncoding)
45 : {
46 0 : mEncoding = aEncoding;
47 0 : mHasEncoding = true;
48 0 : }
49 :
50 : const nsAString&
51 0 : GetEncoding() const
52 : {
53 0 : return mEncoding;
54 : }
55 :
56 : bool
57 0 : HasEncoding() const
58 : {
59 0 : return mHasEncoding;
60 : }
61 :
62 : void
63 : FireProgressEvent(uint64_t aLoaded, uint64_t aTotal);
64 :
65 : void
66 : SetResultCallback(ResultCallback* aCallback);
67 :
68 : // WebIDL
69 : IDBFileHandle*
70 0 : GetFileHandle() const
71 : {
72 0 : AssertIsOnOwningThread();
73 0 : return mFileHandle;
74 : }
75 :
76 : IDBFileHandle*
77 0 : GetLockedFile() const
78 : {
79 0 : AssertIsOnOwningThread();
80 0 : return GetFileHandle();
81 : }
82 :
83 0 : IMPL_EVENT_HANDLER(progress)
84 :
85 : void
86 0 : AssertIsOnOwningThread() const
87 : {
88 0 : NS_ASSERT_OWNINGTHREAD(IDBFileRequest);
89 0 : }
90 :
91 : NS_DECL_ISUPPORTS_INHERITED
92 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBFileRequest, DOMRequest)
93 :
94 : // nsIDOMEventTarget
95 : virtual nsresult
96 : GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
97 :
98 : // nsWrapperCache
99 : virtual JSObject*
100 : WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
101 :
102 : private:
103 : IDBFileRequest(IDBFileHandle* aFileHandle,
104 : bool aWrapAsDOMRequest);
105 :
106 : ~IDBFileRequest();
107 : };
108 :
109 : class NS_NO_VTABLE IDBFileRequest::ResultCallback
110 : {
111 : public:
112 : virtual nsresult
113 : GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult) = 0;
114 :
115 : protected:
116 0 : ResultCallback()
117 0 : { }
118 : };
119 :
120 : } // namespace dom
121 : } // namespace mozilla
122 :
123 : #endif // mozilla_dom_idbfilerequest_h__
|