PushSubscription.h (2589B)
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/. */ 6 7 #ifndef mozilla_dom_PushSubscription_h 8 #define mozilla_dom_PushSubscription_h 9 10 #include "domstubs.h" 11 #include "js/RootingAPI.h" 12 #include "mozilla/AlreadyAddRefed.h" 13 #include "mozilla/RefPtr.h" 14 #include "mozilla/dom/BindingDeclarations.h" 15 #include "mozilla/dom/PushSubscriptionBinding.h" 16 #include "mozilla/dom/PushSubscriptionOptionsBinding.h" 17 #include "mozilla/dom/TypedArray.h" 18 #include "nsCOMPtr.h" 19 #include "nsWrapperCache.h" 20 21 class nsIGlobalObject; 22 23 namespace mozilla { 24 class ErrorResult; 25 26 namespace dom { 27 28 class Promise; 29 30 class PushSubscription final : public nsISupports, public nsWrapperCache { 31 public: 32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 33 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(PushSubscription) 34 35 PushSubscription(nsIGlobalObject* aGlobal, const nsAString& aEndpoint, 36 const nsAString& aScope, 37 Nullable<EpochTimeStamp>&& aExpirationTime, 38 nsTArray<uint8_t>&& aP256dhKey, 39 nsTArray<uint8_t>&& aAuthSecret, 40 nsTArray<uint8_t>&& aAppServerKey); 41 42 JSObject* WrapObject(JSContext* aCx, 43 JS::Handle<JSObject*> aGivenProto) override; 44 45 nsIGlobalObject* GetParentObject() const { return mGlobal; } 46 47 void GetEndpoint(nsAString& aEndpoint) const { aEndpoint = mEndpoint; } 48 49 void GetKey(JSContext* cx, PushEncryptionKeyName aType, 50 JS::MutableHandle<JSObject*> aKey, ErrorResult& aRv); 51 52 Nullable<EpochTimeStamp> GetExpirationTime() { return mExpirationTime; }; 53 54 static already_AddRefed<PushSubscription> Constructor( 55 GlobalObject& aGlobal, const PushSubscriptionInit& aInitDict, 56 ErrorResult& aRv); 57 58 already_AddRefed<Promise> Unsubscribe(ErrorResult& aRv); 59 60 void ToJSON(PushSubscriptionJSON& aJSON, ErrorResult& aRv); 61 62 already_AddRefed<PushSubscriptionOptions> Options(); 63 64 private: 65 ~PushSubscription(); 66 67 already_AddRefed<Promise> UnsubscribeFromWorker(ErrorResult& aRv); 68 69 nsString mEndpoint; 70 nsString mScope; 71 Nullable<EpochTimeStamp> mExpirationTime; 72 nsTArray<uint8_t> mRawP256dhKey; 73 nsTArray<uint8_t> mAuthSecret; 74 nsCOMPtr<nsIGlobalObject> mGlobal; 75 RefPtr<PushSubscriptionOptions> mOptions; 76 }; 77 78 } // namespace dom 79 } // namespace mozilla 80 81 #endif // mozilla_dom_PushSubscription_h