tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 62795c77d763101812f1b32416342c95510077df
parent 9e90e5f01e3375672d6cec20810500d812d51eb5
Author: Harveer Singh <hsingh@mozilla.com>
Date:   Mon,  3 Nov 2025 22:49:22 +0000

Bug 1989386: Correctly update serviceworker type on re-registration.r=edenchuang,dom-worker-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D265665

Diffstat:
Mdom/serviceworkers/ServiceWorkerRegisterJob.cpp | 11++++++++---
Mdom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp | 4++++
Mdom/serviceworkers/ServiceWorkerRegistrationDescriptor.h | 2++
Mdom/serviceworkers/ServiceWorkerRegistrationInfo.cpp | 11++++++-----
Mdom/serviceworkers/ServiceWorkerRegistrationInfo.h | 6++++--
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