Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #ifndef mozilla_dom_PushSubscription_h
6 : #define mozilla_dom_PushSubscription_h
7 :
8 : #include "jsapi.h"
9 : #include "nsCOMPtr.h"
10 : #include "nsWrapperCache.h"
11 : #include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
12 :
13 : #include "mozilla/AlreadyAddRefed.h"
14 : #include "mozilla/ErrorResult.h"
15 : #include "mozilla/RefPtr.h"
16 :
17 : #include "mozilla/dom/BindingDeclarations.h"
18 : #include "mozilla/dom/PushSubscriptionBinding.h"
19 : #include "mozilla/dom/PushSubscriptionOptionsBinding.h"
20 : #include "mozilla/dom/TypedArray.h"
21 :
22 : class nsIGlobalObject;
23 :
24 : namespace mozilla {
25 : namespace dom {
26 :
27 : namespace workers {
28 : class WorkerPrivate;
29 : }
30 :
31 : class Promise;
32 :
33 : class PushSubscription final : public nsISupports
34 : , public nsWrapperCache
35 : {
36 : public:
37 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
38 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushSubscription)
39 :
40 : PushSubscription(nsIGlobalObject* aGlobal,
41 : const nsAString& aEndpoint,
42 : const nsAString& aScope,
43 : nsTArray<uint8_t>&& aP256dhKey,
44 : nsTArray<uint8_t>&& aAuthSecret,
45 : nsTArray<uint8_t>&& aAppServerKey);
46 :
47 : JSObject*
48 : WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
49 :
50 : nsIGlobalObject*
51 0 : GetParentObject() const
52 : {
53 0 : return mGlobal;
54 : }
55 :
56 : void
57 0 : GetEndpoint(nsAString& aEndpoint) const
58 : {
59 0 : aEndpoint = mEndpoint;
60 0 : }
61 :
62 : void
63 : GetKey(JSContext* cx,
64 : PushEncryptionKeyName aType,
65 : JS::MutableHandle<JSObject*> aKey,
66 : ErrorResult& aRv);
67 :
68 : static already_AddRefed<PushSubscription>
69 : Constructor(GlobalObject& aGlobal,
70 : const PushSubscriptionInit& aInitDict,
71 : ErrorResult& aRv);
72 :
73 : already_AddRefed<Promise>
74 : Unsubscribe(ErrorResult& aRv);
75 :
76 : void
77 : ToJSON(PushSubscriptionJSON& aJSON, ErrorResult& aRv);
78 :
79 : already_AddRefed<PushSubscriptionOptions>
80 : Options();
81 :
82 : private:
83 : ~PushSubscription();
84 :
85 : already_AddRefed<Promise>
86 : UnsubscribeFromWorker(ErrorResult& aRv);
87 :
88 : nsString mEndpoint;
89 : nsString mScope;
90 : nsTArray<uint8_t> mRawP256dhKey;
91 : nsTArray<uint8_t> mAuthSecret;
92 : nsCOMPtr<nsIGlobalObject> mGlobal;
93 : RefPtr<PushSubscriptionOptions> mOptions;
94 : };
95 :
96 : } // namespace dom
97 : } // namespace mozilla
98 :
99 : #endif // mozilla_dom_PushSubscription_h
|