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 : #include "mozilla/dom/PushSubscriptionOptions.h"
6 :
7 : #include "mozilla/dom/PushSubscriptionOptionsBinding.h"
8 : #include "mozilla/HoldDropJSObjects.h"
9 :
10 : namespace mozilla {
11 : namespace dom {
12 :
13 0 : PushSubscriptionOptions::PushSubscriptionOptions(nsIGlobalObject* aGlobal,
14 0 : nsTArray<uint8_t>&& aRawAppServerKey)
15 : : mGlobal(aGlobal)
16 0 : , mRawAppServerKey(Move(aRawAppServerKey))
17 0 : , mAppServerKey(nullptr)
18 : {
19 : // There's only one global on a worker, so we don't need to pass a global
20 : // object to the constructor.
21 0 : MOZ_ASSERT_IF(NS_IsMainThread(), mGlobal);
22 0 : mozilla::HoldJSObjects(this);
23 0 : }
24 :
25 0 : PushSubscriptionOptions::~PushSubscriptionOptions()
26 : {
27 0 : mAppServerKey = nullptr;
28 0 : mozilla::DropJSObjects(this);
29 0 : }
30 :
31 : NS_IMPL_CYCLE_COLLECTION_CLASS(PushSubscriptionOptions)
32 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(PushSubscriptionOptions)
33 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
34 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
35 0 : tmp->mAppServerKey = nullptr;
36 0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
37 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(PushSubscriptionOptions)
38 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
39 0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
40 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(PushSubscriptionOptions)
41 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
42 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mAppServerKey)
43 0 : NS_IMPL_CYCLE_COLLECTION_TRACE_END
44 :
45 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(PushSubscriptionOptions)
46 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(PushSubscriptionOptions)
47 :
48 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PushSubscriptionOptions)
49 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
50 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
51 0 : NS_INTERFACE_MAP_END
52 :
53 : JSObject*
54 0 : PushSubscriptionOptions::WrapObject(JSContext* aCx,
55 : JS::Handle<JSObject*> aGivenProto)
56 : {
57 0 : return PushSubscriptionOptionsBinding::Wrap(aCx, this, aGivenProto);
58 : }
59 :
60 : void
61 0 : PushSubscriptionOptions::GetApplicationServerKey(JSContext* aCx,
62 : JS::MutableHandle<JSObject*> aKey,
63 : ErrorResult& aRv)
64 : {
65 0 : if (!mRawAppServerKey.IsEmpty() && !mAppServerKey) {
66 0 : JS::Rooted<JSObject*> appServerKey(aCx);
67 0 : PushUtil::CopyArrayToArrayBuffer(aCx, mRawAppServerKey, &appServerKey, aRv);
68 0 : if (aRv.Failed()) {
69 0 : return;
70 : }
71 0 : MOZ_ASSERT(appServerKey);
72 0 : mAppServerKey = appServerKey;
73 : }
74 0 : aKey.set(mAppServerKey);
75 : }
76 :
77 : } // namespace dom
78 : } // namespace mozilla
|