commit bd63d6b6d089285c01836514ca9a4066dd0d3468 parent 9f740083c944b0a03ca5f6a0e4106eec31fb8583 Author: Harveer Singh <hsingh@mozilla.com> Date: Sun, 2 Nov 2025 14:13:47 +0000 Bug 1989386: Correctly update serviceworker type on re-registration.r=edenchuang,dom-worker-reviewers Differential Revision: https://phabricator.services.mozilla.com/D265665 Diffstat:
5 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/dom/serviceworkers/ServiceWorkerRegisterJob.cpp b/dom/serviceworkers/ServiceWorkerRegisterJob.cpp @@ -36,11 +36,16 @@ void ServiceWorkerRegisterJob::AsyncExecute() { swm->GetRegistration(mPrincipal, mScope); if (registration) { - bool sameUVC = GetUpdateViaCache() == registration->GetUpdateViaCache(); - registration->SetUpdateViaCache(GetUpdateViaCache()); + // if registration already exists, comparing it's options to see if + // they have been changed + bool sameOptions = + GetUpdateViaCache() == registration->GetUpdateViaCache() && + mType == registration->Type(); + + registration->SetOptions(GetUpdateViaCache(), mType); RefPtr<ServiceWorkerInfo> newest = registration->Newest(); - if (newest && mScriptSpec.Equals(newest->ScriptSpec()) && sameUVC) { + if (newest && mScriptSpec.Equals(newest->ScriptSpec()) && sameOptions) { SetRegistration(registration); Finish(NS_OK); return; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp b/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp @@ -242,6 +242,10 @@ void ServiceWorkerRegistrationDescriptor::SetUpdateViaCache( mData->updateViaCache() = aUpdateViaCache; } +void ServiceWorkerRegistrationDescriptor::SetWorkerType(WorkerType aType) { + mData->type() = aType; +} + void ServiceWorkerRegistrationDescriptor::SetWorkers( ServiceWorkerInfo* aInstalling, ServiceWorkerInfo* aWaiting, ServiceWorkerInfo* aActive) { diff --git a/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.h b/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.h @@ -93,6 +93,8 @@ class ServiceWorkerRegistrationDescriptor final { void SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache); + void SetWorkerType(WorkerType aType); + void SetWorkers(ServiceWorkerInfo* aInstalling, ServiceWorkerInfo* aWaiting, ServiceWorkerInfo* aActive); diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp b/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp @@ -452,11 +452,11 @@ bool ServiceWorkerRegistrationInfo::IsLastUpdateCheckTimeOverOneDay() const { } void ServiceWorkerRegistrationInfo::UpdateRegistrationState() { - UpdateRegistrationState(mDescriptor.UpdateViaCache()); + UpdateRegistrationState(mDescriptor.UpdateViaCache(), mDescriptor.Type()); } void ServiceWorkerRegistrationInfo::UpdateRegistrationState( - ServiceWorkerUpdateViaCache aUpdateViaCache) { + ServiceWorkerUpdateViaCache aUpdateViaCache, WorkerType aType) { MOZ_ASSERT(NS_IsMainThread()); TimeStamp oldest = TimeStamp::Now() - TimeDuration::FromSeconds(30); @@ -478,6 +478,7 @@ void ServiceWorkerRegistrationInfo::UpdateRegistrationState( mDescriptor.SetWorkers(mInstallingWorker, mWaitingWorker, mActiveWorker); mDescriptor.SetUpdateViaCache(aUpdateViaCache); + mDescriptor.SetWorkerType(aType); for (RefPtr<ServiceWorkerRegistrationListener> pinnedTarget : mInstanceList.ForwardRange()) { @@ -768,9 +769,9 @@ ServiceWorkerUpdateViaCache ServiceWorkerRegistrationInfo::GetUpdateViaCache() return mDescriptor.UpdateViaCache(); } -void ServiceWorkerRegistrationInfo::SetUpdateViaCache( - ServiceWorkerUpdateViaCache aUpdateViaCache) { - UpdateRegistrationState(aUpdateViaCache); +void ServiceWorkerRegistrationInfo::SetOptions( + ServiceWorkerUpdateViaCache aUpdateViaCache, WorkerType aType) { + UpdateRegistrationState(aUpdateViaCache, aType); } int64_t ServiceWorkerRegistrationInfo::GetLastUpdateTime() const { diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.h b/dom/serviceworkers/ServiceWorkerRegistrationInfo.h @@ -225,7 +225,8 @@ class ServiceWorkerRegistrationInfo final ServiceWorkerUpdateViaCache GetUpdateViaCache() const; - void SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache); + void SetOptions(ServiceWorkerUpdateViaCache aUpdateViaCache, + WorkerType aType); int64_t GetLastUpdateTime() const; @@ -259,7 +260,8 @@ class ServiceWorkerRegistrationInfo final // may get CC-ed. void UpdateRegistrationState(); - void UpdateRegistrationState(ServiceWorkerUpdateViaCache aUpdateViaCache); + void UpdateRegistrationState(ServiceWorkerUpdateViaCache aUpdateViaCache, + WorkerType aType); // Used by devtools to track changes to the properties of // *nsIServiceWorkerRegistrationInfo*. Note, this doesn't necessarily need to