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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_PushSubscription_h
8 #define mozilla_dom_PushSubscription_h
10 #include "js/RootingAPI.h"
12 #include "nsWrapperCache.h"
14 #include "mozilla/AlreadyAddRefed.h"
15 #include "mozilla/RefPtr.h"
17 #include "mozilla/dom/BindingDeclarations.h"
18 #include "mozilla/dom/PushSubscriptionBinding.h"
19 #include "mozilla/dom/PushSubscriptionOptionsBinding.h"
20 #include "mozilla/dom/TypedArray.h"
23 class nsIGlobalObject
;
32 class PushSubscription final
: public nsISupports
, public nsWrapperCache
{
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PushSubscription
)
37 PushSubscription(nsIGlobalObject
* aGlobal
, const nsAString
& aEndpoint
,
38 const nsAString
& aScope
,
39 Nullable
<EpochTimeStamp
>&& aExpirationTime
,
40 nsTArray
<uint8_t>&& aP256dhKey
,
41 nsTArray
<uint8_t>&& aAuthSecret
,
42 nsTArray
<uint8_t>&& aAppServerKey
);
44 JSObject
* WrapObject(JSContext
* aCx
,
45 JS::Handle
<JSObject
*> aGivenProto
) override
;
47 nsIGlobalObject
* GetParentObject() const { return mGlobal
; }
49 void GetEndpoint(nsAString
& aEndpoint
) const { aEndpoint
= mEndpoint
; }
51 void GetKey(JSContext
* cx
, PushEncryptionKeyName aType
,
52 JS::MutableHandle
<JSObject
*> aKey
, ErrorResult
& aRv
);
54 Nullable
<EpochTimeStamp
> GetExpirationTime() { return mExpirationTime
; };
56 static already_AddRefed
<PushSubscription
> Constructor(
57 GlobalObject
& aGlobal
, const PushSubscriptionInit
& aInitDict
,
60 already_AddRefed
<Promise
> Unsubscribe(ErrorResult
& aRv
);
62 void ToJSON(PushSubscriptionJSON
& aJSON
, ErrorResult
& aRv
);
64 already_AddRefed
<PushSubscriptionOptions
> Options();
69 already_AddRefed
<Promise
> UnsubscribeFromWorker(ErrorResult
& aRv
);
73 Nullable
<EpochTimeStamp
> mExpirationTime
;
74 nsTArray
<uint8_t> mRawP256dhKey
;
75 nsTArray
<uint8_t> mAuthSecret
;
76 nsCOMPtr
<nsIGlobalObject
> mGlobal
;
77 RefPtr
<PushSubscriptionOptions
> mOptions
;
81 } // namespace mozilla
83 #endif // mozilla_dom_PushSubscription_h