Coverage Report

Created: 2018-09-25 14:53

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