commit e813c3de2fea2d819aaa5df4e71d49b81ccbd0fc parent 2b4f2ed60e7c2105be7d000aabb227f1771e3308 Author: Harveer Singh <hsingh@mozilla.com> Date: Sun, 2 Nov 2025 14:13:46 +0000 Bug 1360870: Some source code plumbing and refactorings to support new serviceworker type.r=edenchuang,dom-worker-reviewers Differential Revision: https://phabricator.services.mozilla.com/D264455 Diffstat:
22 files changed, 108 insertions(+), 61 deletions(-)
diff --git a/dom/serviceworkers/ServiceWorker.cpp b/dom/serviceworkers/ServiceWorker.cpp @@ -85,7 +85,7 @@ ServiceWorker::ServiceWorker(nsIGlobalObject* aGlobal, RefPtr<ServiceWorkerRegistration> reg = aGlobal->GetServiceWorkerRegistration(ServiceWorkerRegistrationDescriptor( mDescriptor.RegistrationId(), mDescriptor.RegistrationVersion(), - mDescriptor.PrincipalInfo(), mDescriptor.Scope(), + mDescriptor.PrincipalInfo(), mDescriptor.Scope(), mDescriptor.Type(), ServiceWorkerUpdateViaCache::Imports)); if (reg) { diff --git a/dom/serviceworkers/ServiceWorkerContainer.cpp b/dom/serviceworkers/ServiceWorkerContainer.cpp @@ -318,7 +318,7 @@ already_AddRefed<Promise> ServiceWorkerContainer::Register( } mActor->SendRegister( - clientInfo.ref().ToIPC(), nsCString(cleanedScopeURL), + clientInfo.ref().ToIPC(), nsCString(cleanedScopeURL), aOptions.mType, nsCString(cleanedScriptURL), aOptions.mUpdateViaCache, [self, outer](const IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult& diff --git a/dom/serviceworkers/ServiceWorkerContainerParent.cpp b/dom/serviceworkers/ServiceWorkerContainerParent.cpp @@ -22,7 +22,7 @@ void ServiceWorkerContainerParent::ActorDestroy(ActorDestroyReason aReason) { IPCResult ServiceWorkerContainerParent::RecvRegister( const IPCClientInfo& aClientInfo, const nsACString& aScopeURL, - const nsACString& aScriptURL, + const WorkerType& aType, const nsACString& aScriptURL, const ServiceWorkerUpdateViaCache& aUpdateViaCache, RegisterResolver&& aResolver) { if (!mProxy) { @@ -31,7 +31,7 @@ IPCResult ServiceWorkerContainerParent::RecvRegister( } mProxy - ->Register(ClientInfo(aClientInfo), aScopeURL, aScriptURL, + ->Register(ClientInfo(aClientInfo), aScopeURL, aType, aScriptURL, aUpdateViaCache) ->Then( GetCurrentSerialEventTarget(), __func__, diff --git a/dom/serviceworkers/ServiceWorkerContainerParent.h b/dom/serviceworkers/ServiceWorkerContainerParent.h @@ -25,7 +25,7 @@ class ServiceWorkerContainerParent final mozilla::ipc::IPCResult RecvRegister( const IPCClientInfo& aClientInfo, const nsACString& aScopeURL, - const nsACString& aScriptURL, + const WorkerType& aType, const nsACString& aScriptURL, const ServiceWorkerUpdateViaCache& aUpdateViaCache, RegisterResolver&& aResolver) override; diff --git a/dom/serviceworkers/ServiceWorkerContainerProxy.cpp b/dom/serviceworkers/ServiceWorkerContainerProxy.cpp @@ -42,7 +42,8 @@ void ServiceWorkerContainerProxy::RevokeActor( RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerContainerProxy::Register( const ClientInfo& aClientInfo, const nsACString& aScopeURL, - const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache) { + const WorkerType& aType, const nsACString& aScriptURL, + ServiceWorkerUpdateViaCache aUpdateViaCache) { AssertIsOnBackgroundThread(); RefPtr<ServiceWorkerRegistrationPromise::Private> promise = @@ -50,7 +51,7 @@ RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerContainerProxy::Register( nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction( __func__, - [aClientInfo, aScopeURL = nsCString(aScopeURL), + [aClientInfo, aScopeURL = nsCString(aScopeURL), aType, aScriptURL = nsCString(aScriptURL), aUpdateViaCache, promise]() mutable { auto scopeExit = MakeScopeExit( [&] { promise->Reject(NS_ERROR_DOM_INVALID_STATE_ERR, __func__); }); @@ -58,7 +59,8 @@ RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerContainerProxy::Register( RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); NS_ENSURE_TRUE_VOID(swm); - swm->Register(aClientInfo, aScopeURL, aScriptURL, aUpdateViaCache) + swm->Register(aClientInfo, aScopeURL, aType, aScriptURL, + aUpdateViaCache) ->ChainTo(promise.forget(), __func__); scopeExit.release(); diff --git a/dom/serviceworkers/ServiceWorkerContainerProxy.h b/dom/serviceworkers/ServiceWorkerContainerProxy.h @@ -27,7 +27,7 @@ class ServiceWorkerContainerProxy final { RefPtr<ServiceWorkerRegistrationPromise> Register( const ClientInfo& aClientInfo, const nsACString& aScopeURL, - const nsACString& aScriptURL, + const WorkerType& aType, const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache); RefPtr<ServiceWorkerRegistrationPromise> GetRegistration( diff --git a/dom/serviceworkers/ServiceWorkerDescriptor.cpp b/dom/serviceworkers/ServiceWorkerDescriptor.cpp @@ -8,6 +8,7 @@ #include "mozilla/dom/IPCServiceWorkerDescriptor.h" #include "mozilla/dom/ServiceWorkerBinding.h" +#include "mozilla/dom/WorkerBinding.h" #include "mozilla/ipc/PBackgroundSharedTypes.h" namespace mozilla::dom { @@ -17,7 +18,7 @@ using mozilla::ipc::PrincipalInfoToPrincipal; ServiceWorkerDescriptor::ServiceWorkerDescriptor( uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, - nsIPrincipal* aPrincipal, const nsACString& aScope, + nsIPrincipal* aPrincipal, const nsACString& aScope, WorkerType aType, const nsACString& aScriptURL, ServiceWorkerState aState) : mData(MakeUnique<IPCServiceWorkerDescriptor>()) { MOZ_ALWAYS_SUCCEEDS( @@ -27,6 +28,7 @@ ServiceWorkerDescriptor::ServiceWorkerDescriptor( mData->registrationId() = aRegistrationId; mData->registrationVersion() = aRegistrationVersion; mData->scope() = aScope; + mData->type() = aType; mData->scriptURL() = aScriptURL; mData->state() = aState; // Set HandlesFetch as true in default @@ -36,10 +38,10 @@ ServiceWorkerDescriptor::ServiceWorkerDescriptor( ServiceWorkerDescriptor::ServiceWorkerDescriptor( uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const nsACString& aScope, - const nsACString& aScriptURL, ServiceWorkerState aState) + WorkerType aType, const nsACString& aScriptURL, ServiceWorkerState aState) : mData(MakeUnique<IPCServiceWorkerDescriptor>( aId, aRegistrationId, aRegistrationVersion, aPrincipalInfo, - nsCString(aScriptURL), nsCString(aScope), aState, true)) {} + nsCString(aScriptURL), aType, nsCString(aScope), aState, true)) {} ServiceWorkerDescriptor::ServiceWorkerDescriptor( const IPCServiceWorkerDescriptor& aDescriptor) @@ -103,6 +105,8 @@ const nsCString& ServiceWorkerDescriptor::Scope() const { return mData->scope(); } +WorkerType ServiceWorkerDescriptor::Type() const { return mData->type(); } + const nsCString& ServiceWorkerDescriptor::ScriptURL() const { return mData->scriptURL(); } diff --git a/dom/serviceworkers/ServiceWorkerDescriptor.h b/dom/serviceworkers/ServiceWorkerDescriptor.h @@ -21,6 +21,7 @@ class PrincipalInfo; namespace dom { class IPCServiceWorkerDescriptor; +enum class WorkerType : uint8_t; enum class ServiceWorkerState : uint8_t; // This class represents a snapshot of a particular ServiceWorkerInfo object. @@ -37,13 +38,13 @@ class ServiceWorkerDescriptor final { ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, nsIPrincipal* aPrincipal, const nsACString& aScope, - const nsACString& aScriptURL, + WorkerType aType, const nsACString& aScriptURL, ServiceWorkerState aState); ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, - const nsACString& aScope, + const nsACString& aScope, WorkerType aType, const nsACString& aScriptURL, ServiceWorkerState aState); @@ -74,6 +75,8 @@ class ServiceWorkerDescriptor final { const nsCString& Scope() const; + WorkerType Type() const; + const nsCString& ScriptURL() const; ServiceWorkerState State() const; diff --git a/dom/serviceworkers/ServiceWorkerIPCUtils.h b/dom/serviceworkers/ServiceWorkerIPCUtils.h @@ -14,6 +14,7 @@ #include "mozilla/dom/BindingIPCUtils.h" #include "mozilla/dom/ServiceWorkerBinding.h" #include "mozilla/dom/ServiceWorkerRegistrationBinding.h" +#include "mozilla/dom/WorkerBinding.h" namespace IPC { diff --git a/dom/serviceworkers/ServiceWorkerInfo.cpp b/dom/serviceworkers/ServiceWorkerInfo.cpp @@ -232,16 +232,15 @@ void ServiceWorkerInfo::UpdateState(ServiceWorkerState aState) { } } -ServiceWorkerInfo::ServiceWorkerInfo(nsIPrincipal* aPrincipal, - const nsACString& aScope, - uint64_t aRegistrationId, - uint64_t aRegistrationVersion, - const nsACString& aScriptSpec, - const nsAString& aCacheName, - nsLoadFlags aImportsLoadFlags) +ServiceWorkerInfo::ServiceWorkerInfo( + nsIPrincipal* aPrincipal, const nsACString& aScope, const WorkerType& aType, + uint64_t aRegistrationId, uint64_t aRegistrationVersion, + const nsACString& aScriptSpec, const nsAString& aCacheName, + nsLoadFlags aImportsLoadFlags) : mPrincipal(aPrincipal), mDescriptor(GetNextID(), aRegistrationId, aRegistrationVersion, - aPrincipal, aScope, aScriptSpec, ServiceWorkerState::Parsed), + aPrincipal, aScope, aType, aScriptSpec, + ServiceWorkerState::Parsed), mCacheName(aCacheName), mWorkerPrivateId(ComputeWorkerPrivateId()), mImportsLoadFlags(aImportsLoadFlags), diff --git a/dom/serviceworkers/ServiceWorkerInfo.h b/dom/serviceworkers/ServiceWorkerInfo.h @@ -91,7 +91,7 @@ class ServiceWorkerInfo final : public nsIServiceWorkerInfo { const nsCString& ScriptSpec() const { return mDescriptor.ScriptURL(); } const nsCString& Scope() const { return mDescriptor.Scope(); } - + WorkerType Type() const { return mDescriptor.Type(); } Maybe<ClientInfo> GetClientInfo(); // Pass-through of ServiceWorkerPrivate::GetLifetimeDeadline(); note that @@ -114,7 +114,8 @@ class ServiceWorkerInfo final : public nsIServiceWorkerInfo { } ServiceWorkerInfo(nsIPrincipal* aPrincipal, const nsACString& aScope, - uint64_t aRegistrationId, uint64_t aRegistrationVersion, + const WorkerType& aType, uint64_t aRegistrationId, + uint64_t aRegistrationVersion, const nsACString& aScriptSpec, const nsAString& aCacheName, nsLoadFlags aImportsLoadFlags); diff --git a/dom/serviceworkers/ServiceWorkerManager.cpp b/dom/serviceworkers/ServiceWorkerManager.cpp @@ -182,6 +182,7 @@ nsresult PopulateRegistrationData( } aData.scope() = aRegistration->Scope(); + aData.type() = aRegistration->Type(); // TODO: When bug 1426401 is implemented we will need to handle more // than just the active worker here. @@ -815,8 +816,10 @@ ServiceWorkerManager::RegisterForTest(nsIPrincipal* aPrincipal, auto scope = NS_ConvertUTF16toUTF8(aScopeURL); auto scriptURL = NS_ConvertUTF16toUTF8(aScriptURL); - auto regPromise = Register(clientInfo.ref(), scope, scriptURL, - dom::ServiceWorkerUpdateViaCache::Imports); + auto regPromise = + Register(clientInfo.ref(), scope, WorkerType::Classic, scriptURL, + dom::ServiceWorkerUpdateViaCache::Imports); + const RefPtr<ServiceWorkerManager> self(this); const nsCOMPtr<nsIPrincipal> principal(aPrincipal); regPromise->Then( @@ -844,7 +847,8 @@ ServiceWorkerManager::RegisterForTest(nsIPrincipal* aPrincipal, RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerManager::Register( const ClientInfo& aClientInfo, const nsACString& aScopeURL, - const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache) { + const WorkerType& aType, const nsACString& aScriptURL, + ServiceWorkerUpdateViaCache aUpdateViaCache) { AUTO_PROFILER_MARKER_UNTYPED("SWM Register", DOM, {}); nsCOMPtr<nsIURI> scopeURI; @@ -897,7 +901,7 @@ RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerManager::Register( auto lifetime = DetermineLifetimeForClient(aClientInfo); RefPtr<ServiceWorkerRegisterJob> job = new ServiceWorkerRegisterJob( - principal, aScopeURL, aScriptURL, + principal, aScopeURL, aType, aScriptURL, static_cast<ServiceWorkerUpdateViaCache>(aUpdateViaCache), lifetime); job->AppendResultCallback(cb); @@ -1640,11 +1644,11 @@ void ServiceWorkerManager::LoadRegistration( RefPtr<ServiceWorkerRegistrationInfo> registration = GetRegistration(principal, aRegistration.scope()); if (!registration) { - registration = - CreateNewRegistration(aRegistration.scope(), principal, - static_cast<ServiceWorkerUpdateViaCache>( - aRegistration.updateViaCache()), - aRegistration.navigationPreloadState()); + registration = CreateNewRegistration( + aRegistration.scope(), aRegistration.type(), principal, + static_cast<ServiceWorkerUpdateViaCache>( + aRegistration.updateViaCache()), + aRegistration.navigationPreloadState()); } else { // If active worker script matches our expectations for a "current worker", // then we are done. Since scripts with the same URL might have different @@ -1669,9 +1673,9 @@ void ServiceWorkerManager::LoadRegistration( const nsCString& currentWorkerURL = aRegistration.currentWorkerURL(); if (!currentWorkerURL.IsEmpty()) { registration->SetActive(new ServiceWorkerInfo( - registration->Principal(), registration->Scope(), registration->Id(), - registration->Version(), currentWorkerURL, aRegistration.cacheName(), - importsLoadFlags)); + registration->Principal(), registration->Scope(), registration->Type(), + registration->Id(), registration->Version(), currentWorkerURL, + aRegistration.cacheName(), importsLoadFlags)); registration->GetActive()->SetHandlesFetch( aRegistration.currentWorkerHandlesFetch()); registration->GetActive()->SetInstalledTime( @@ -2935,9 +2939,10 @@ ServiceWorkerManager::RegisterForAddonPrincipal(nsIPrincipal* aPrincipal, return NS_OK; } - auto regPromise = - Register(clientInfo.ref(), scope, NS_ConvertUTF16toUTF8(scriptURL), - dom::ServiceWorkerUpdateViaCache::Imports); + auto regPromise = Register(clientInfo.ref(), scope, WorkerType::Classic, + NS_ConvertUTF16toUTF8(scriptURL), + dom::ServiceWorkerUpdateViaCache::Imports); + const RefPtr<ServiceWorkerManager> self(this); const nsCOMPtr<nsIPrincipal> principal(aPrincipal); regPromise->Then( @@ -3110,7 +3115,7 @@ ServiceWorkerManager::GetRegistration(const nsACString& aScopeKey, already_AddRefed<ServiceWorkerRegistrationInfo> ServiceWorkerManager::CreateNewRegistration( - const nsCString& aScope, nsIPrincipal* aPrincipal, + const nsCString& aScope, const WorkerType& aType, nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState aNavigationPreloadState) { #ifdef DEBUG @@ -3125,7 +3130,8 @@ ServiceWorkerManager::CreateNewRegistration( #endif RefPtr<ServiceWorkerRegistrationInfo> registration = - new ServiceWorkerRegistrationInfo(aScope, aPrincipal, aUpdateViaCache, + new ServiceWorkerRegistrationInfo(aScope, aType, aPrincipal, + aUpdateViaCache, std::move(aNavigationPreloadState)); // From now on ownership of registration is with diff --git a/dom/serviceworkers/ServiceWorkerManager.h b/dom/serviceworkers/ServiceWorkerManager.h @@ -10,6 +10,7 @@ #include <cstdint> #include "ErrorList.h" +#include "ServiceWorkerDescriptor.h" #include "ServiceWorkerShutdownState.h" #include "js/ErrorReport.h" #include "mozilla/AlreadyAddRefed.h" @@ -176,7 +177,7 @@ class ServiceWorkerManager final : public nsIServiceWorkerManager, RefPtr<ServiceWorkerRegistrationPromise> Register( const ClientInfo& aClientInfo, const nsACString& aScopeURL, - const nsACString& aScriptURL, + const WorkerType& aType, const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache); RefPtr<ServiceWorkerRegistrationPromise> GetRegistration( @@ -193,8 +194,8 @@ class ServiceWorkerManager final : public nsIServiceWorkerManager, const nsACString& aScope) const; already_AddRefed<ServiceWorkerRegistrationInfo> CreateNewRegistration( - const nsCString& aScope, nsIPrincipal* aPrincipal, - ServiceWorkerUpdateViaCache aUpdateViaCache, + const nsCString& aScope, const WorkerType& aType, + nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState aNavigationPreloadState = IPCNavigationPreloadState(false, "true"_ns)); diff --git a/dom/serviceworkers/ServiceWorkerPrivate.cpp b/dom/serviceworkers/ServiceWorkerPrivate.cpp @@ -743,9 +743,13 @@ nsresult ServiceWorkerPrivate::Initialize() { mClientInfo->SetURL(mInfo->ScriptSpec()); mClientInfo->SetFrameType(FrameType::None); + WorkerOptions workerOptions; + workerOptions.mCredentials = RequestCredentials::Omit; + workerOptions.mType = mInfo->Type(); + mRemoteWorkerData = RemoteWorkerData( NS_ConvertUTF8toUTF16(mInfo->ScriptSpec()), baseScriptURL, baseScriptURL, - WorkerOptions(), + workerOptions, /* loading principal */ principalInfo, principalInfo, partitionedPrincipalInfo, /* useRegularPrincipal */ true, diff --git a/dom/serviceworkers/ServiceWorkerRegisterJob.cpp b/dom/serviceworkers/ServiceWorkerRegisterJob.cpp @@ -13,12 +13,13 @@ namespace mozilla::dom { ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( - nsIPrincipal* aPrincipal, const nsACString& aScope, + nsIPrincipal* aPrincipal, const nsACString& aScope, const WorkerType& aType, const nsACString& aScriptSpec, ServiceWorkerUpdateViaCache aUpdateViaCache, const ServiceWorkerLifetimeExtension& aLifetimeExtension) : ServiceWorkerUpdateJob(Type::Register, aPrincipal, aScope, nsCString(aScriptSpec), aUpdateViaCache, - aLifetimeExtension) {} + aLifetimeExtension), + mType(aType) {} void ServiceWorkerRegisterJob::AsyncExecute() { MOZ_ASSERT(NS_IsMainThread()); @@ -45,8 +46,8 @@ void ServiceWorkerRegisterJob::AsyncExecute() { return; } } else { - registration = - swm->CreateNewRegistration(mScope, mPrincipal, GetUpdateViaCache()); + registration = swm->CreateNewRegistration(mScope, mType, mPrincipal, + GetUpdateViaCache()); if (!registration) { FailUpdateJob(NS_ERROR_DOM_ABORT_ERR); return; diff --git a/dom/serviceworkers/ServiceWorkerRegisterJob.h b/dom/serviceworkers/ServiceWorkerRegisterJob.h @@ -18,11 +18,13 @@ class ServiceWorkerRegisterJob final : public ServiceWorkerUpdateJob { public: ServiceWorkerRegisterJob( nsIPrincipal* aPrincipal, const nsACString& aScope, - const nsACString& aScriptSpec, + const WorkerType& aType, const nsACString& aScriptSpec, ServiceWorkerUpdateViaCache aUpdateViaCache, const ServiceWorkerLifetimeExtension& aLifetimeExtension); private: + WorkerType mType; + // Implement the Register algorithm steps and then call the parent class // Update() to complete the job execution. virtual void AsyncExecute() override; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp b/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp @@ -30,7 +30,8 @@ ServiceWorkerRegistrationDescriptor::NewestInternal() const { ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, nsIPrincipal* aPrincipal, - const nsACString& aScope, ServiceWorkerUpdateViaCache aUpdateViaCache) + const nsACString& aScope, WorkerType aType, + ServiceWorkerUpdateViaCache aUpdateViaCache) : mData(MakeUnique<IPCServiceWorkerRegistrationDescriptor>()) { MOZ_ALWAYS_SUCCEEDS( PrincipalToPrincipalInfo(aPrincipal, &mData->principalInfo())); @@ -38,6 +39,7 @@ ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( mData->id() = aId; mData->version() = aVersion; mData->scope() = aScope; + mData->type() = aType; mData->updateViaCache() = aUpdateViaCache; mData->installing() = Nothing(); mData->waiting() = Nothing(); @@ -47,10 +49,10 @@ ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const nsACString& aScope, - ServiceWorkerUpdateViaCache aUpdateViaCache) + WorkerType aType, ServiceWorkerUpdateViaCache aUpdateViaCache) : mData(MakeUnique<IPCServiceWorkerRegistrationDescriptor>( - aId, aVersion, aPrincipalInfo, nsCString(aScope), aUpdateViaCache, - Nothing(), Nothing(), Nothing())) {} + aId, aVersion, aPrincipalInfo, nsCString(aScope), aType, + aUpdateViaCache, Nothing(), Nothing(), Nothing())) {} ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( const IPCServiceWorkerRegistrationDescriptor& aDescriptor) @@ -130,6 +132,10 @@ const nsCString& ServiceWorkerRegistrationDescriptor::Scope() const { return mData->scope(); } +WorkerType ServiceWorkerRegistrationDescriptor::Type() const { + return mData->type(); +} + Maybe<ServiceWorkerDescriptor> ServiceWorkerRegistrationDescriptor::GetInstalling() const { Maybe<ServiceWorkerDescriptor> result; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.h b/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.h @@ -9,6 +9,7 @@ #include "mozilla/Maybe.h" #include "mozilla/UniquePtr.h" #include "mozilla/dom/ServiceWorkerDescriptor.h" +#include "mozilla/dom/WorkerBinding.h" namespace mozilla { @@ -36,12 +37,14 @@ class ServiceWorkerRegistrationDescriptor final { public: ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, nsIPrincipal* aPrincipal, - const nsACString& aScope, ServiceWorkerUpdateViaCache aUpdateViaCache); + const nsACString& aScope, WorkerType aType, + ServiceWorkerUpdateViaCache aUpdateViaCache); ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, - const nsACString& aScope, ServiceWorkerUpdateViaCache aUpdateViaCache); + const nsACString& aScope, WorkerType aType, + ServiceWorkerUpdateViaCache aUpdateViaCache); explicit ServiceWorkerRegistrationDescriptor( const IPCServiceWorkerRegistrationDescriptor& aDescriptor); @@ -74,6 +77,8 @@ class ServiceWorkerRegistrationDescriptor final { const nsCString& Scope() const; + WorkerType Type() const; + Maybe<ServiceWorkerDescriptor> GetInstalling() const; Maybe<ServiceWorkerDescriptor> GetWaiting() const; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp b/dom/serviceworkers/ServiceWorkerRegistrationInfo.cpp @@ -70,11 +70,11 @@ void ServiceWorkerRegistrationInfo::ClearAsCorrupt() { bool ServiceWorkerRegistrationInfo::IsCorrupt() const { return mCorrupt; } ServiceWorkerRegistrationInfo::ServiceWorkerRegistrationInfo( - const nsACString& aScope, nsIPrincipal* aPrincipal, + const nsACString& aScope, WorkerType aType, nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState&& aNavigationPreloadState) : mPrincipal(aPrincipal), - mDescriptor(GetNextId(), GetNextVersion(), aPrincipal, aScope, + mDescriptor(GetNextId(), GetNextVersion(), aPrincipal, aScope, aType, aUpdateViaCache), mControlledClientsCounter(0), mDelayMultiplier(0), @@ -130,6 +130,10 @@ const nsCString& ServiceWorkerRegistrationInfo::Scope() const { return mDescriptor.Scope(); } +WorkerType ServiceWorkerRegistrationInfo::Type() const { + return mDescriptor.Type(); +} + nsIPrincipal* ServiceWorkerRegistrationInfo::Principal() const { return mPrincipal; } diff --git a/dom/serviceworkers/ServiceWorkerRegistrationInfo.h b/dom/serviceworkers/ServiceWorkerRegistrationInfo.h @@ -81,7 +81,7 @@ class ServiceWorkerRegistrationInfo final using TryToActivateCallback = std::function<void()>; ServiceWorkerRegistrationInfo( - const nsACString& aScope, nsIPrincipal* aPrincipal, + const nsACString& aScope, WorkerType aType, nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState&& aNavigationPreloadState); @@ -100,6 +100,8 @@ class ServiceWorkerRegistrationInfo final const nsCString& Scope() const; + WorkerType Type() const; + nsIPrincipal* Principal() const; bool IsUnregistered() const; diff --git a/dom/serviceworkers/ServiceWorkerUpdateJob.cpp b/dom/serviceworkers/ServiceWorkerUpdateJob.cpp @@ -418,8 +418,9 @@ void ServiceWorkerUpdateJob::ComparisonResult(nsresult aStatus, } RefPtr<ServiceWorkerInfo> sw = new ServiceWorkerInfo( - mRegistration->Principal(), mRegistration->Scope(), mRegistration->Id(), - mRegistration->Version(), mScriptSpec, aNewCacheName, flags); + mRegistration->Principal(), mRegistration->Scope(), mRegistration->Type(), + mRegistration->Id(), mRegistration->Version(), mScriptSpec, aNewCacheName, + flags); // If the registration is corrupt enough to force an uninstall if the // upgrade fails, then we want to make sure the upgrade takes effect diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp @@ -1146,6 +1146,11 @@ nsresult WorkerScriptLoader::FillCompileOptionsForRequest( aOptions->setSourceMapURL(aRequest->GetSourceMapURL().get()); } + // disable top-level await for module scripts + if (mWorkerRef->Private()->IsServiceWorker() && aRequest->IsModuleRequest()) { + aOptions->topLevelAwait = false; + } + return NS_OK; }