Bug 1434342 P3 Make each ServiceWorker DOM object automatically fire its statechange event when appropriate. r=asuth

This commit is contained in:
Ben Kelly 2018-01-31 09:10:26 -08:00
Родитель 7427e49f90
Коммит 2508c997c6
3 изменённых файлов: 4 добавлений и 16 удалений

Просмотреть файл

@ -107,7 +107,11 @@ ServiceWorker::State() const
void
ServiceWorker::SetState(ServiceWorkerState aState)
{
ServiceWorkerState oldState = mDescriptor.State();
mDescriptor.SetState(aState);
if (oldState != aState) {
DOMEventTargetHelper::DispatchTrustedEvent(NS_LITERAL_STRING("statechange"));
}
}
void
@ -116,12 +120,6 @@ ServiceWorker::GetScriptURL(nsString& aURL) const
CopyUTF8toUTF16(mDescriptor.ScriptURL(), aURL);
}
void
ServiceWorker::DispatchStateChange(ServiceWorkerState aState)
{
DOMEventTargetHelper::DispatchTrustedEvent(NS_LITERAL_STRING("statechange"));
}
void
ServiceWorker::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
const Sequence<JSObject*>& aTransferable,

Просмотреть файл

@ -47,9 +47,6 @@ public:
void
GetScriptURL(nsString& aURL) const;
void
DispatchStateChange(ServiceWorkerState aState);
#ifdef XP_WIN
#undef PostMessage
#endif

Просмотреть файл

@ -159,16 +159,9 @@ public:
NS_IMETHOD Run() override
{
// We need to update the state of all instances atomically before notifying
// them to make sure that the observed state for all instances inside
// statechange event handlers is correct.
for (size_t i = 0; i < mInstances.Length(); ++i) {
mInstances[i]->SetState(mState);
}
for (size_t i = 0; i < mInstances.Length(); ++i) {
mInstances[i]->DispatchStateChange(mState);
}
return NS_OK;
}