Bug 1434342 P6 Make ServiceWorker call nsIGlobalObject::AddServiceWorker and RemoveServiceWorker. r=asuth

This commit is contained in:
Ben Kelly 2018-01-31 09:10:26 -08:00
parent 0ff28a0a92
commit 9dfb987159
2 changed files with 20 additions and 0 deletions

View File

@ -73,8 +73,11 @@ ServiceWorker::ServiceWorker(nsIGlobalObject* aGlobal,
, mInner(aInner)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_DIAGNOSTIC_ASSERT(aGlobal);
MOZ_DIAGNOSTIC_ASSERT(mInner);
aGlobal->AddServiceWorker(this);
// This will update our state too.
mInner->AddServiceWorker(this);
}
@ -83,6 +86,10 @@ ServiceWorker::~ServiceWorker()
{
MOZ_ASSERT(NS_IsMainThread());
mInner->RemoveServiceWorker(this);
nsIGlobalObject* global = GetParentObject();
if (global) {
global->RemoveServiceWorker(this);
}
}
NS_IMPL_ADDREF_INHERITED(ServiceWorker, DOMEventTargetHelper)
@ -145,5 +152,15 @@ ServiceWorker::MatchesDescriptor(const ServiceWorkerDescriptor& aDescriptor) con
mDescriptor.Id() == aDescriptor.Id();
}
void
ServiceWorker::DisconnectFromOwner()
{
nsIGlobalObject* global = GetParentObject();
if (global) {
global->RemoveServiceWorker(this);
}
DOMEventTargetHelper::DisconnectFromOwner();
}
} // namespace dom
} // namespace mozilla

View File

@ -86,6 +86,9 @@ public:
bool
MatchesDescriptor(const ServiceWorkerDescriptor& aDescriptor) const;
void
DisconnectFromOwner() override;
private:
ServiceWorker(nsIGlobalObject* aWindow,
const ServiceWorkerDescriptor& aDescriptor,