Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/serviceworkers/ServiceWorkerDescriptor.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 "ServiceWorkerDescriptor.h"
8
#include "mozilla/dom/IPCServiceWorkerDescriptor.h"
9
#include "mozilla/dom/ServiceWorkerBinding.h"
10
#include "mozilla/ipc/PBackgroundSharedTypes.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
using mozilla::ipc::PrincipalInfo;
16
using mozilla::ipc::PrincipalInfoToPrincipal;
17
18
ServiceWorkerDescriptor::ServiceWorkerDescriptor(uint64_t aId,
19
                                                 uint64_t aRegistrationId,
20
                                                 uint64_t aRegistrationVersion,
21
                                                 nsIPrincipal* aPrincipal,
22
                                                 const nsACString& aScope,
23
                                                 const nsACString& aScriptURL,
24
                                                 ServiceWorkerState aState)
25
  : mData(MakeUnique<IPCServiceWorkerDescriptor>())
26
0
{
27
0
  MOZ_ALWAYS_SUCCEEDS(
28
0
    PrincipalToPrincipalInfo(aPrincipal, &mData->principalInfo()));
29
0
30
0
  mData->id() = aId;
31
0
  mData->registrationId() = aRegistrationId;
32
0
  mData->registrationVersion() = aRegistrationVersion;
33
0
  mData->scope() = aScope;
34
0
  mData->scriptURL() = aScriptURL;
35
0
  mData->state() = aState;
36
0
}
37
38
ServiceWorkerDescriptor::ServiceWorkerDescriptor(uint64_t aId,
39
                                                 uint64_t aRegistrationId,
40
                                                 uint64_t aRegistrationVersion,
41
                                                 const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
42
                                                 const nsACString& aScope,
43
                                                 const nsACString& aScriptURL,
44
                                                 ServiceWorkerState aState)
45
  : mData(MakeUnique<IPCServiceWorkerDescriptor>(aId, aRegistrationId,
46
                                                 aRegistrationVersion,
47
                                                 aPrincipalInfo,
48
                                                 nsCString(aScriptURL),
49
                                                 nsCString(aScope), aState))
50
0
{
51
0
}
52
53
ServiceWorkerDescriptor::ServiceWorkerDescriptor(const IPCServiceWorkerDescriptor& aDescriptor)
54
  : mData(MakeUnique<IPCServiceWorkerDescriptor>(aDescriptor))
55
0
{
56
0
}
57
58
ServiceWorkerDescriptor::ServiceWorkerDescriptor(const ServiceWorkerDescriptor& aRight)
59
0
{
60
0
  operator=(aRight);
61
0
}
62
63
ServiceWorkerDescriptor&
64
ServiceWorkerDescriptor::operator=(const ServiceWorkerDescriptor& aRight)
65
0
{
66
0
  if (this == &aRight) {
67
0
    return *this;
68
0
  }
69
0
  mData.reset();
70
0
  mData = MakeUnique<IPCServiceWorkerDescriptor>(*aRight.mData);
71
0
  return *this;
72
0
}
73
74
ServiceWorkerDescriptor::ServiceWorkerDescriptor(ServiceWorkerDescriptor&& aRight)
75
  : mData(std::move(aRight.mData))
76
0
{
77
0
}
78
79
ServiceWorkerDescriptor&
80
ServiceWorkerDescriptor::operator=(ServiceWorkerDescriptor&& aRight)
81
0
{
82
0
  mData.reset();
83
0
  mData = std::move(aRight.mData);
84
0
  return *this;
85
0
}
86
87
ServiceWorkerDescriptor::~ServiceWorkerDescriptor()
88
0
{
89
0
}
90
91
bool
92
ServiceWorkerDescriptor::operator==(const ServiceWorkerDescriptor& aRight) const
93
0
{
94
0
  return *mData == *aRight.mData;
95
0
}
96
97
uint64_t
98
ServiceWorkerDescriptor::Id() const
99
0
{
100
0
  return mData->id();
101
0
}
102
103
uint64_t
104
ServiceWorkerDescriptor::RegistrationId() const
105
0
{
106
0
  return mData->registrationId();
107
0
}
108
109
uint64_t
110
ServiceWorkerDescriptor::RegistrationVersion() const
111
0
{
112
0
  return mData->registrationVersion();
113
0
}
114
115
const mozilla::ipc::PrincipalInfo&
116
ServiceWorkerDescriptor::PrincipalInfo() const
117
0
{
118
0
  return mData->principalInfo();
119
0
}
120
121
nsCOMPtr<nsIPrincipal>
122
ServiceWorkerDescriptor::GetPrincipal() const
123
0
{
124
0
  AssertIsOnMainThread();
125
0
  nsCOMPtr<nsIPrincipal> ref =  PrincipalInfoToPrincipal(mData->principalInfo());
126
0
  return ref;
127
0
}
128
129
const nsCString&
130
ServiceWorkerDescriptor::Scope() const
131
0
{
132
0
  return mData->scope();
133
0
}
134
135
const nsCString&
136
ServiceWorkerDescriptor::ScriptURL() const
137
0
{
138
0
  return mData->scriptURL();
139
0
}
140
141
ServiceWorkerState
142
ServiceWorkerDescriptor::State() const
143
0
{
144
0
  return mData->state();
145
0
}
146
147
void
148
ServiceWorkerDescriptor::SetState(ServiceWorkerState aState)
149
0
{
150
0
  mData->state() = aState;
151
0
}
152
153
void
154
ServiceWorkerDescriptor::SetRegistrationVersion(uint64_t aVersion)
155
0
{
156
0
  MOZ_DIAGNOSTIC_ASSERT(aVersion > mData->registrationVersion());
157
0
  mData->registrationVersion() = aVersion;
158
0
}
159
160
bool
161
ServiceWorkerDescriptor::Matches(const ServiceWorkerDescriptor& aDescriptor) const
162
0
{
163
0
  return Id() == aDescriptor.Id() &&
164
0
         Scope() == aDescriptor.Scope() &&
165
0
         ScriptURL() == aDescriptor.ScriptURL() &&
166
0
         PrincipalInfo() == aDescriptor.PrincipalInfo();
167
0
}
168
169
const IPCServiceWorkerDescriptor&
170
ServiceWorkerDescriptor::ToIPC() const
171
0
{
172
0
  return *mData;
173
0
}
174
175
} // namespace dom
176
} // namespace mozilla