Source code

Revision control

Other Tools

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(
19
uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion,
20
nsIPrincipal* aPrincipal, const nsACString& aScope,
21
const nsACString& aScriptURL, ServiceWorkerState aState)
22
: mData(MakeUnique<IPCServiceWorkerDescriptor>()) {
23
MOZ_ALWAYS_SUCCEEDS(
24
PrincipalToPrincipalInfo(aPrincipal, &mData->principalInfo()));
25
26
mData->id() = aId;
27
mData->registrationId() = aRegistrationId;
28
mData->registrationVersion() = aRegistrationVersion;
29
mData->scope() = aScope;
30
mData->scriptURL() = aScriptURL;
31
mData->state() = aState;
32
}
33
34
ServiceWorkerDescriptor::ServiceWorkerDescriptor(
35
uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion,
36
const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const nsACString& aScope,
37
const nsACString& aScriptURL, ServiceWorkerState aState)
38
: mData(MakeUnique<IPCServiceWorkerDescriptor>(
39
aId, aRegistrationId, aRegistrationVersion, aPrincipalInfo,
40
nsCString(aScriptURL), nsCString(aScope), aState)) {}
41
42
ServiceWorkerDescriptor::ServiceWorkerDescriptor(
43
const IPCServiceWorkerDescriptor& aDescriptor)
44
: mData(MakeUnique<IPCServiceWorkerDescriptor>(aDescriptor)) {}
45
46
ServiceWorkerDescriptor::ServiceWorkerDescriptor(
47
const ServiceWorkerDescriptor& aRight) {
48
operator=(aRight);
49
}
50
51
ServiceWorkerDescriptor& ServiceWorkerDescriptor::operator=(
52
const ServiceWorkerDescriptor& aRight) {
53
if (this == &aRight) {
54
return *this;
55
}
56
mData.reset();
57
mData = MakeUnique<IPCServiceWorkerDescriptor>(*aRight.mData);
58
return *this;
59
}
60
61
ServiceWorkerDescriptor::ServiceWorkerDescriptor(
62
ServiceWorkerDescriptor&& aRight)
63
: mData(std::move(aRight.mData)) {}
64
65
ServiceWorkerDescriptor& ServiceWorkerDescriptor::operator=(
66
ServiceWorkerDescriptor&& aRight) {
67
mData.reset();
68
mData = std::move(aRight.mData);
69
return *this;
70
}
71
72
ServiceWorkerDescriptor::~ServiceWorkerDescriptor() {}
73
74
bool ServiceWorkerDescriptor::operator==(
75
const ServiceWorkerDescriptor& aRight) const {
76
return *mData == *aRight.mData;
77
}
78
79
uint64_t ServiceWorkerDescriptor::Id() const { return mData->id(); }
80
81
uint64_t ServiceWorkerDescriptor::RegistrationId() const {
82
return mData->registrationId();
83
}
84
85
uint64_t ServiceWorkerDescriptor::RegistrationVersion() const {
86
return mData->registrationVersion();
87
}
88
89
const mozilla::ipc::PrincipalInfo& ServiceWorkerDescriptor::PrincipalInfo()
90
const {
91
return mData->principalInfo();
92
}
93
94
nsCOMPtr<nsIPrincipal> ServiceWorkerDescriptor::GetPrincipal() const {
95
AssertIsOnMainThread();
96
nsCOMPtr<nsIPrincipal> ref = PrincipalInfoToPrincipal(mData->principalInfo());
97
return ref;
98
}
99
100
const nsCString& ServiceWorkerDescriptor::Scope() const {
101
return mData->scope();
102
}
103
104
const nsCString& ServiceWorkerDescriptor::ScriptURL() const {
105
return mData->scriptURL();
106
}
107
108
ServiceWorkerState ServiceWorkerDescriptor::State() const {
109
return mData->state();
110
}
111
112
void ServiceWorkerDescriptor::SetState(ServiceWorkerState aState) {
113
mData->state() = aState;
114
}
115
116
void ServiceWorkerDescriptor::SetRegistrationVersion(uint64_t aVersion) {
117
MOZ_DIAGNOSTIC_ASSERT(aVersion > mData->registrationVersion());
118
mData->registrationVersion() = aVersion;
119
}
120
121
bool ServiceWorkerDescriptor::Matches(
122
const ServiceWorkerDescriptor& aDescriptor) const {
123
return Id() == aDescriptor.Id() && Scope() == aDescriptor.Scope() &&
124
ScriptURL() == aDescriptor.ScriptURL() &&
125
PrincipalInfo() == aDescriptor.PrincipalInfo();
126
}
127
128
const IPCServiceWorkerDescriptor& ServiceWorkerDescriptor::ToIPC() const {
129
return *mData;
130
}
131
132
} // namespace dom
133
} // namespace mozilla