Bug 1914585 - Remove legacy method ForgetAboutThisSite.removeDataFromDomain. r=hsohan...
[gecko.git] / dom / push / PushSubscriptionOptions.cpp
blobb14afa310d6e8965b8d54e67043c8706340648ee
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 #include "mozilla/dom/PushSubscriptionOptions.h"
9 #include "MainThreadUtils.h"
10 #include "mozilla/dom/PushSubscriptionOptionsBinding.h"
11 #include "mozilla/dom/TypedArray.h"
12 #include "mozilla/ErrorResult.h"
13 #include "mozilla/HoldDropJSObjects.h"
14 #include "nsIGlobalObject.h"
15 #include "nsWrapperCache.h"
17 namespace mozilla::dom {
19 PushSubscriptionOptions::PushSubscriptionOptions(
20 nsIGlobalObject* aGlobal, nsTArray<uint8_t>&& aRawAppServerKey)
21 : mGlobal(aGlobal),
22 mRawAppServerKey(std::move(aRawAppServerKey)),
23 mAppServerKey(nullptr) {
24 // There's only one global on a worker, so we don't need to pass a global
25 // object to the constructor.
26 MOZ_ASSERT_IF(NS_IsMainThread(), mGlobal);
27 mozilla::HoldJSObjects(this);
30 PushSubscriptionOptions::~PushSubscriptionOptions() {
31 mozilla::DropJSObjects(this);
34 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS(PushSubscriptionOptions,
35 (mGlobal),
36 (mAppServerKey))
38 NS_IMPL_CYCLE_COLLECTING_ADDREF(PushSubscriptionOptions)
39 NS_IMPL_CYCLE_COLLECTING_RELEASE(PushSubscriptionOptions)
41 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PushSubscriptionOptions)
42 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
43 NS_INTERFACE_MAP_ENTRY(nsISupports)
44 NS_INTERFACE_MAP_END
46 JSObject* PushSubscriptionOptions::WrapObject(
47 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
48 return PushSubscriptionOptions_Binding::Wrap(aCx, this, aGivenProto);
51 void PushSubscriptionOptions::GetApplicationServerKey(
52 JSContext* aCx, JS::MutableHandle<JSObject*> aKey, ErrorResult& aRv) {
53 if (!mRawAppServerKey.IsEmpty() && !mAppServerKey) {
54 mAppServerKey = ArrayBuffer::Create(aCx, mRawAppServerKey, aRv);
55 if (aRv.Failed()) {
56 return;
59 aKey.set(mAppServerKey);
62 } // namespace mozilla::dom