tor-browser

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

commit 285b305de4a1358d9df033f104c9cf5fe204686b
parent d83412ca1f6c78b5a8ea9225e9d1d74dcf269dfc
Author: Atila Butkovits <abutkovits@mozilla.com>
Date:   Thu, 30 Oct 2025 00:01:19 +0200

Revert "Bug 1360870, Bug 1995558, Bug 1990925, Bug 1989386: Test changes.r=edenchuang,dom-worker-reviewers" for causing failures at browser_dbg-browser-toolbox-workers.js.

This reverts commit 5308d85d1342b4ce4721100a319bec1cd2d03ef0.

Revert "Bug 1995558: Service worker module registration should be rejected in case of any evaluation errors.r=edenchuang,dom-worker-reviewers"

This reverts commit 262e9c7f2213b5884baaeea39cd01e12041337f3.

Revert "Bug 1990925: Module service workers should be able to load json modules.r=edenchuang,dom-worker-reviewers"

This reverts commit 5e00fd86aaa0f57938bdc58e57daaaae80995a2f.

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

This reverts commit 137e22f4402eb7939b30724ca7271664f59a1ed0.

Revert "Bug 1360870: on-disk schema changes to persist new serviceworker type parameter.r=edenchuang,dom-worker-reviewers"

This reverts commit bf551670f43fd2576802584a37bd4d66cb6eee7f.

Revert "Bug 1360870: Some source code plumbing and refactorings to support new serviceworker type.r=edenchuang,dom-worker-reviewers"

This reverts commit 040663a23b2fd939acff1c4bb1cf1a86519221ee.

Revert "Bug 1360870: idl changes to support module service workers.r=asuth,edenchuang,webidl,smaug,dom-worker-reviewers"

This reverts commit c8854f0a27252c5a22df63ffee8d8efb327f6e9c.

Diffstat:
Mdom/serviceworkers/IPCServiceWorkerDescriptor.ipdlh | 3---
Mdom/serviceworkers/IPCServiceWorkerRegistrationDescriptor.ipdlh | 4+---
Mdom/serviceworkers/PServiceWorkerContainer.ipdl | 7+++----
Mdom/serviceworkers/ServiceWorker.cpp | 2+-
Mdom/serviceworkers/ServiceWorkerContainer.cpp | 2+-
Mdom/serviceworkers/ServiceWorkerContainerParent.cpp | 4++--
Mdom/serviceworkers/ServiceWorkerContainerParent.h | 2+-
Mdom/serviceworkers/ServiceWorkerContainerProxy.cpp | 8+++-----
Mdom/serviceworkers/ServiceWorkerContainerProxy.h | 2+-
Mdom/serviceworkers/ServiceWorkerDescriptor.cpp | 10+++-------
Mdom/serviceworkers/ServiceWorkerDescriptor.h | 7++-----
Mdom/serviceworkers/ServiceWorkerIPCUtils.h | 1-
Mdom/serviceworkers/ServiceWorkerInfo.cpp | 15++++++++-------
Mdom/serviceworkers/ServiceWorkerInfo.h | 5++---
Mdom/serviceworkers/ServiceWorkerManager.cpp | 40+++++++++++++++++-----------------------
Mdom/serviceworkers/ServiceWorkerManager.h | 7+++----
Mdom/serviceworkers/ServiceWorkerPrivate.cpp | 7+------
Mdom/serviceworkers/ServiceWorkerRegisterJob.cpp | 20+++++++-------------
Mdom/serviceworkers/ServiceWorkerRegisterJob.h | 4+---
Mdom/serviceworkers/ServiceWorkerRegistrar.cpp | 114+++++++++++++++++++++++++++++++++++--------------------------------------------
Mdom/serviceworkers/ServiceWorkerRegistrar.h | 2+-
Mdom/serviceworkers/ServiceWorkerRegistrarTypes.ipdlh | 9---------
Mdom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp | 18++++--------------
Mdom/serviceworkers/ServiceWorkerRegistrationDescriptor.h | 11++---------
Mdom/serviceworkers/ServiceWorkerRegistrationInfo.cpp | 19+++++++------------
Mdom/serviceworkers/ServiceWorkerRegistrationInfo.h | 10+++-------
Mdom/serviceworkers/ServiceWorkerScriptCache.cpp | 9++++-----
Mdom/serviceworkers/ServiceWorkerUpdateJob.cpp | 5++---
Mdom/serviceworkers/test/gtest/TestReadWrite.cpp | 35++++++++++++++---------------------
Mdom/webidl/ServiceWorkerContainer.webidl | 1-
Mdom/workers/ScriptLoader.cpp | 5-----
Mdom/workers/loader/NetworkLoadHandler.cpp | 30+++++++++++++-----------------
Mdom/workers/loader/WorkerModuleLoader.cpp | 5-----
Mdom/workers/loader/WorkerModuleLoader.h | 2--
Mjs/loader/ModuleLoaderBase.cpp | 16+---------------
Mjs/loader/ModuleLoaderBase.h | 2--
Mnetwerk/protocol/http/HttpBaseChannel.cpp | 11+----------
Mtesting/web-platform/meta/html/cross-origin-embedder-policy/reflection-credentialless.tentative.https.any.js.ini | 3+--
Mtesting/web-platform/meta/html/cross-origin-embedder-policy/reflection-require-corp.tentative.https.any.js.ini | 3+--
Mtesting/web-platform/meta/html/cross-origin-embedder-policy/reflection-unsafe-none.tentative.https.any.js.ini | 3+--
Mtesting/web-platform/meta/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https.html.ini | 6++----
Mtesting/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-object.any.js.ini | 2++
Mtesting/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve.any.js.ini | 5+++++
Mtesting/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-url.any.js.ini | 4+---
Mtesting/web-platform/meta/infrastructure/server/context.any.js.ini | 3+--
Atesting/web-platform/meta/service-workers/service-worker/no-dynamic-import-in-module.any.js.ini | 4++++
Atesting/web-platform/meta/service-workers/service-worker/registration-scope-module-static-import.https.html.ini | 9+++++++++
Mtesting/web-platform/meta/service-workers/service-worker/registration-script-module.https.html.ini | 3+--
Mtesting/web-platform/meta/service-workers/service-worker/registration-script.https.html.ini | 4++--
Mtesting/web-platform/meta/service-workers/service-worker/update-bytecheck-cors-import.https.html.ini | 11+++++++++++
Mtesting/web-platform/meta/service-workers/service-worker/update-bytecheck.https.html.ini | 11+++++++++--
Mtesting/web-platform/meta/service-workers/service-worker/update-registration-with-type.https.html.ini | 6++++++
Mtesting/web-platform/tests/infrastructure/metadata/infrastructure/server/context.any.js.ini | 6+++---
Mtesting/web-platform/tests/service-workers/service-worker/resources/registration-tests-script.js | 8++++----
54 files changed, 223 insertions(+), 322 deletions(-)

diff --git a/dom/serviceworkers/IPCServiceWorkerDescriptor.ipdlh b/dom/serviceworkers/IPCServiceWorkerDescriptor.ipdlh @@ -5,10 +5,8 @@ include PBackgroundSharedTypes; include "mozilla/dom/ServiceWorkerIPCUtils.h"; -include "mozilla/dom/WorkerIPCUtils.h"; using mozilla::dom::ServiceWorkerState from "mozilla/dom/ServiceWorkerBinding.h"; -using mozilla::dom::WorkerType from "mozilla/dom/WorkerBinding.h"; namespace mozilla { namespace dom { @@ -23,7 +21,6 @@ namespace dom { uint64_t registrationVersion; PrincipalInfo principalInfo; nsCString scope; - WorkerType type; nsCString scriptURL; ServiceWorkerState state; bool handlesFetch; diff --git a/dom/serviceworkers/IPCServiceWorkerRegistrationDescriptor.ipdlh b/dom/serviceworkers/IPCServiceWorkerRegistrationDescriptor.ipdlh @@ -7,11 +7,9 @@ include IPCServiceWorkerDescriptor; include "ipc/ErrorIPCUtils.h"; include "mozilla/dom/ServiceWorkerIPCUtils.h"; -include "mozilla/dom/WorkerIPCUtils.h"; using mozilla::dom::ServiceWorkerUpdateViaCache from "mozilla/dom/ServiceWorkerRegistrationBinding.h"; using mozilla::CopyableErrorResult from "mozilla/ErrorResult.h"; -using mozilla::dom::WorkerType from "mozilla/dom/WorkerBinding.h"; namespace mozilla { namespace dom { @@ -31,7 +29,7 @@ namespace dom { // worker is installed yet, etc. PrincipalInfo principalInfo; nsCString scope; - WorkerType type; + ServiceWorkerUpdateViaCache updateViaCache; IPCServiceWorkerDescriptor? installing; diff --git a/dom/serviceworkers/PServiceWorkerContainer.ipdl b/dom/serviceworkers/PServiceWorkerContainer.ipdl @@ -6,9 +6,8 @@ include protocol PBackground; include ClientIPCTypes; include IPCServiceWorkerRegistrationDescriptor; -include "mozilla/dom/WorkerIPCUtils.h"; -using mozilla::dom::WorkerType from "mozilla/dom/WorkerBinding.h"; +include "mozilla/dom/ServiceWorkerIPCUtils.h"; namespace mozilla { namespace dom { @@ -19,8 +18,8 @@ protocol PServiceWorkerContainer manager PBackground; parent: - async Register(IPCClientInfo aClientInfo, nsCString aScopeURL, WorkerType aType, - nsCString aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache) + async Register(IPCClientInfo aClientInfo, nsCString aScopeURL, nsCString aScriptURL, + ServiceWorkerUpdateViaCache aUpdateViaCache) returns (IPCServiceWorkerRegistrationDescriptorOrCopyableErrorResult aResult); async GetRegistration(IPCClientInfo aClientInfo, nsCString aURL) 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.Type(), + mDescriptor.PrincipalInfo(), mDescriptor.Scope(), 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), aOptions.mType, + clientInfo.ref().ToIPC(), nsCString(cleanedScopeURL), 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 WorkerType& aType, const nsACString& aScriptURL, + const nsACString& aScriptURL, const ServiceWorkerUpdateViaCache& aUpdateViaCache, RegisterResolver&& aResolver) { if (!mProxy) { @@ -31,7 +31,7 @@ IPCResult ServiceWorkerContainerParent::RecvRegister( } mProxy - ->Register(ClientInfo(aClientInfo), aScopeURL, aType, aScriptURL, + ->Register(ClientInfo(aClientInfo), aScopeURL, 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 WorkerType& aType, const nsACString& aScriptURL, + const nsACString& aScriptURL, const ServiceWorkerUpdateViaCache& aUpdateViaCache, RegisterResolver&& aResolver) override; diff --git a/dom/serviceworkers/ServiceWorkerContainerProxy.cpp b/dom/serviceworkers/ServiceWorkerContainerProxy.cpp @@ -42,8 +42,7 @@ void ServiceWorkerContainerProxy::RevokeActor( RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerContainerProxy::Register( const ClientInfo& aClientInfo, const nsACString& aScopeURL, - const WorkerType& aType, const nsACString& aScriptURL, - ServiceWorkerUpdateViaCache aUpdateViaCache) { + const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache) { AssertIsOnBackgroundThread(); RefPtr<ServiceWorkerRegistrationPromise::Private> promise = @@ -51,7 +50,7 @@ RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerContainerProxy::Register( nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction( __func__, - [aClientInfo, aScopeURL = nsCString(aScopeURL), aType, + [aClientInfo, aScopeURL = nsCString(aScopeURL), aScriptURL = nsCString(aScriptURL), aUpdateViaCache, promise]() mutable { auto scopeExit = MakeScopeExit( [&] { promise->Reject(NS_ERROR_DOM_INVALID_STATE_ERR, __func__); }); @@ -59,8 +58,7 @@ RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerContainerProxy::Register( RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); NS_ENSURE_TRUE_VOID(swm); - swm->Register(aClientInfo, aScopeURL, aType, aScriptURL, - aUpdateViaCache) + swm->Register(aClientInfo, aScopeURL, 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 WorkerType& aType, const nsACString& aScriptURL, + const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache); RefPtr<ServiceWorkerRegistrationPromise> GetRegistration( diff --git a/dom/serviceworkers/ServiceWorkerDescriptor.cpp b/dom/serviceworkers/ServiceWorkerDescriptor.cpp @@ -8,7 +8,6 @@ #include "mozilla/dom/IPCServiceWorkerDescriptor.h" #include "mozilla/dom/ServiceWorkerBinding.h" -#include "mozilla/dom/WorkerBinding.h" #include "mozilla/ipc/PBackgroundSharedTypes.h" namespace mozilla::dom { @@ -18,7 +17,7 @@ using mozilla::ipc::PrincipalInfoToPrincipal; ServiceWorkerDescriptor::ServiceWorkerDescriptor( uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, - nsIPrincipal* aPrincipal, const nsACString& aScope, WorkerType aType, + nsIPrincipal* aPrincipal, const nsACString& aScope, const nsACString& aScriptURL, ServiceWorkerState aState) : mData(MakeUnique<IPCServiceWorkerDescriptor>()) { MOZ_ALWAYS_SUCCEEDS( @@ -28,7 +27,6 @@ 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 @@ -38,10 +36,10 @@ ServiceWorkerDescriptor::ServiceWorkerDescriptor( ServiceWorkerDescriptor::ServiceWorkerDescriptor( uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const nsACString& aScope, - WorkerType aType, const nsACString& aScriptURL, ServiceWorkerState aState) + const nsACString& aScriptURL, ServiceWorkerState aState) : mData(MakeUnique<IPCServiceWorkerDescriptor>( aId, aRegistrationId, aRegistrationVersion, aPrincipalInfo, - nsCString(aScriptURL), aType, nsCString(aScope), aState, true)) {} + nsCString(aScriptURL), nsCString(aScope), aState, true)) {} ServiceWorkerDescriptor::ServiceWorkerDescriptor( const IPCServiceWorkerDescriptor& aDescriptor) @@ -105,8 +103,6 @@ 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,7 +21,6 @@ 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. @@ -38,13 +37,13 @@ class ServiceWorkerDescriptor final { ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, nsIPrincipal* aPrincipal, const nsACString& aScope, - WorkerType aType, const nsACString& aScriptURL, + const nsACString& aScriptURL, ServiceWorkerState aState); ServiceWorkerDescriptor(uint64_t aId, uint64_t aRegistrationId, uint64_t aRegistrationVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, - const nsACString& aScope, WorkerType aType, + const nsACString& aScope, const nsACString& aScriptURL, ServiceWorkerState aState); @@ -75,8 +74,6 @@ 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,7 +14,6 @@ #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,15 +232,16 @@ void ServiceWorkerInfo::UpdateState(ServiceWorkerState aState) { } } -ServiceWorkerInfo::ServiceWorkerInfo( - nsIPrincipal* aPrincipal, const nsACString& aScope, const WorkerType& aType, - uint64_t aRegistrationId, uint64_t aRegistrationVersion, - const nsACString& aScriptSpec, const nsAString& aCacheName, - nsLoadFlags aImportsLoadFlags) +ServiceWorkerInfo::ServiceWorkerInfo(nsIPrincipal* aPrincipal, + const nsACString& aScope, + uint64_t aRegistrationId, + uint64_t aRegistrationVersion, + const nsACString& aScriptSpec, + const nsAString& aCacheName, + nsLoadFlags aImportsLoadFlags) : mPrincipal(aPrincipal), mDescriptor(GetNextID(), aRegistrationId, aRegistrationVersion, - aPrincipal, aScope, aType, aScriptSpec, - ServiceWorkerState::Parsed), + aPrincipal, aScope, 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,8 +114,7 @@ class ServiceWorkerInfo final : public nsIServiceWorkerInfo { } ServiceWorkerInfo(nsIPrincipal* aPrincipal, const nsACString& aScope, - const WorkerType& aType, uint64_t aRegistrationId, - uint64_t aRegistrationVersion, + 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,7 +182,6 @@ 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. @@ -816,10 +815,8 @@ ServiceWorkerManager::RegisterForTest(nsIPrincipal* aPrincipal, auto scope = NS_ConvertUTF16toUTF8(aScopeURL); auto scriptURL = NS_ConvertUTF16toUTF8(aScriptURL); - auto regPromise = - Register(clientInfo.ref(), scope, WorkerType::Classic, scriptURL, - dom::ServiceWorkerUpdateViaCache::Imports); - + auto regPromise = Register(clientInfo.ref(), scope, scriptURL, + dom::ServiceWorkerUpdateViaCache::Imports); const RefPtr<ServiceWorkerManager> self(this); const nsCOMPtr<nsIPrincipal> principal(aPrincipal); regPromise->Then( @@ -847,8 +844,7 @@ ServiceWorkerManager::RegisterForTest(nsIPrincipal* aPrincipal, RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerManager::Register( const ClientInfo& aClientInfo, const nsACString& aScopeURL, - const WorkerType& aType, const nsACString& aScriptURL, - ServiceWorkerUpdateViaCache aUpdateViaCache) { + const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache) { AUTO_PROFILER_MARKER_UNTYPED("SWM Register", DOM, {}); nsCOMPtr<nsIURI> scopeURI; @@ -901,7 +897,7 @@ RefPtr<ServiceWorkerRegistrationPromise> ServiceWorkerManager::Register( auto lifetime = DetermineLifetimeForClient(aClientInfo); RefPtr<ServiceWorkerRegisterJob> job = new ServiceWorkerRegisterJob( - principal, aScopeURL, aType, aScriptURL, + principal, aScopeURL, aScriptURL, static_cast<ServiceWorkerUpdateViaCache>(aUpdateViaCache), lifetime); job->AppendResultCallback(cb); @@ -1644,11 +1640,11 @@ void ServiceWorkerManager::LoadRegistration( RefPtr<ServiceWorkerRegistrationInfo> registration = GetRegistration(principal, aRegistration.scope()); if (!registration) { - registration = CreateNewRegistration( - aRegistration.scope(), aRegistration.type(), principal, - static_cast<ServiceWorkerUpdateViaCache>( - aRegistration.updateViaCache()), - aRegistration.navigationPreloadState()); + registration = + CreateNewRegistration(aRegistration.scope(), 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 @@ -1673,9 +1669,9 @@ void ServiceWorkerManager::LoadRegistration( const nsCString& currentWorkerURL = aRegistration.currentWorkerURL(); if (!currentWorkerURL.IsEmpty()) { registration->SetActive(new ServiceWorkerInfo( - registration->Principal(), registration->Scope(), registration->Type(), - registration->Id(), registration->Version(), currentWorkerURL, - aRegistration.cacheName(), importsLoadFlags)); + registration->Principal(), registration->Scope(), registration->Id(), + registration->Version(), currentWorkerURL, aRegistration.cacheName(), + importsLoadFlags)); registration->GetActive()->SetHandlesFetch( aRegistration.currentWorkerHandlesFetch()); registration->GetActive()->SetInstalledTime( @@ -2939,10 +2935,9 @@ ServiceWorkerManager::RegisterForAddonPrincipal(nsIPrincipal* aPrincipal, return NS_OK; } - auto regPromise = Register(clientInfo.ref(), scope, WorkerType::Classic, - NS_ConvertUTF16toUTF8(scriptURL), - dom::ServiceWorkerUpdateViaCache::Imports); - + auto regPromise = + Register(clientInfo.ref(), scope, NS_ConvertUTF16toUTF8(scriptURL), + dom::ServiceWorkerUpdateViaCache::Imports); const RefPtr<ServiceWorkerManager> self(this); const nsCOMPtr<nsIPrincipal> principal(aPrincipal); regPromise->Then( @@ -3115,7 +3110,7 @@ ServiceWorkerManager::GetRegistration(const nsACString& aScopeKey, already_AddRefed<ServiceWorkerRegistrationInfo> ServiceWorkerManager::CreateNewRegistration( - const nsCString& aScope, const WorkerType& aType, nsIPrincipal* aPrincipal, + const nsCString& aScope, nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState aNavigationPreloadState) { #ifdef DEBUG @@ -3130,8 +3125,7 @@ ServiceWorkerManager::CreateNewRegistration( #endif RefPtr<ServiceWorkerRegistrationInfo> registration = - new ServiceWorkerRegistrationInfo(aScope, aType, aPrincipal, - aUpdateViaCache, + new ServiceWorkerRegistrationInfo(aScope, 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,7 +10,6 @@ #include <cstdint> #include "ErrorList.h" -#include "ServiceWorkerDescriptor.h" #include "ServiceWorkerShutdownState.h" #include "js/ErrorReport.h" #include "mozilla/AlreadyAddRefed.h" @@ -177,7 +176,7 @@ class ServiceWorkerManager final : public nsIServiceWorkerManager, RefPtr<ServiceWorkerRegistrationPromise> Register( const ClientInfo& aClientInfo, const nsACString& aScopeURL, - const WorkerType& aType, const nsACString& aScriptURL, + const nsACString& aScriptURL, ServiceWorkerUpdateViaCache aUpdateViaCache); RefPtr<ServiceWorkerRegistrationPromise> GetRegistration( @@ -194,8 +193,8 @@ class ServiceWorkerManager final : public nsIServiceWorkerManager, const nsACString& aScope) const; already_AddRefed<ServiceWorkerRegistrationInfo> CreateNewRegistration( - const nsCString& aScope, const WorkerType& aType, - nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, + const nsCString& aScope, nsIPrincipal* aPrincipal, + ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState aNavigationPreloadState = IPCNavigationPreloadState(false, "true"_ns)); diff --git a/dom/serviceworkers/ServiceWorkerPrivate.cpp b/dom/serviceworkers/ServiceWorkerPrivate.cpp @@ -743,14 +743,9 @@ nsresult ServiceWorkerPrivate::Initialize() { mClientInfo->SetURL(mInfo->ScriptSpec()); mClientInfo->SetFrameType(FrameType::None); - WorkerOptions workerOptions; - workerOptions.mCredentials = RequestCredentials::Omit; - workerOptions.mType = mInfo->Type(); - workerOptions.mName = NS_ConvertUTF8toUTF16(mInfo->ScriptSpec()); - 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,13 +13,12 @@ namespace mozilla::dom { ServiceWorkerRegisterJob::ServiceWorkerRegisterJob( - nsIPrincipal* aPrincipal, const nsACString& aScope, const WorkerType& aType, + nsIPrincipal* aPrincipal, const nsACString& aScope, const nsACString& aScriptSpec, ServiceWorkerUpdateViaCache aUpdateViaCache, const ServiceWorkerLifetimeExtension& aLifetimeExtension) : ServiceWorkerUpdateJob(Type::Register, aPrincipal, aScope, nsCString(aScriptSpec), aUpdateViaCache, - aLifetimeExtension), - mType(aType) {} + aLifetimeExtension) {} void ServiceWorkerRegisterJob::AsyncExecute() { MOZ_ASSERT(NS_IsMainThread()); @@ -36,23 +35,18 @@ void ServiceWorkerRegisterJob::AsyncExecute() { swm->GetRegistration(mPrincipal, mScope); if (registration) { - // 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); + bool sameUVC = GetUpdateViaCache() == registration->GetUpdateViaCache(); + registration->SetUpdateViaCache(GetUpdateViaCache()); RefPtr<ServiceWorkerInfo> newest = registration->Newest(); - if (newest && mScriptSpec.Equals(newest->ScriptSpec()) && sameOptions) { + if (newest && mScriptSpec.Equals(newest->ScriptSpec()) && sameUVC) { SetRegistration(registration); Finish(NS_OK); return; } } else { - registration = swm->CreateNewRegistration(mScope, mType, mPrincipal, - GetUpdateViaCache()); + registration = + swm->CreateNewRegistration(mScope, mPrincipal, GetUpdateViaCache()); if (!registration) { FailUpdateJob(NS_ERROR_DOM_ABORT_ERR); return; diff --git a/dom/serviceworkers/ServiceWorkerRegisterJob.h b/dom/serviceworkers/ServiceWorkerRegisterJob.h @@ -18,13 +18,11 @@ class ServiceWorkerRegisterJob final : public ServiceWorkerUpdateJob { public: ServiceWorkerRegisterJob( nsIPrincipal* aPrincipal, const nsACString& aScope, - const WorkerType& aType, const nsACString& aScriptSpec, + 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/ServiceWorkerRegistrar.cpp b/dom/serviceworkers/ServiceWorkerRegistrar.cpp @@ -49,7 +49,7 @@ namespace mozilla::dom { namespace { static const uint32_t gSupportedRegistrarVersions[] = { - SERVICEWORKERREGISTRAR_VERSION, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2}; + SERVICEWORKERREGISTRAR_VERSION, 10, 9, 8, 7, 6, 5, 4, 3, 2}; static const uint32_t kInvalidGeneration = static_cast<uint32_t>(-1); @@ -627,15 +627,43 @@ nsresult ServiceWorkerRegistrar::ReadData() { return NS_ERROR_FAILURE; \ } - // baseSchemaVersion represents the version where major schema changes - // happened and requires a different reading strategy as done below in the - // switch statement. Version 9 is the latest major schema version, versions - // 10 and 11 are just extensions to version 9 and that's why gets processed - // under the same block. - auto baseSchemaVersion = version >= 9 ? 9 : version; - nsAutoCString line; - switch (baseSchemaVersion) { + switch (version) { + // to add new changes to the schema, + // we incremented SERVICEWORKERREGISTRAR_VERSION, + // added new changes on top of existing schema, + // and [[fallthrough]] to the previous one (version 10) + case SERVICEWORKERREGISTRAR_VERSION: { + nsAutoCString numberOfAttemptedActivationsStr; + GET_LINE(numberOfAttemptedActivationsStr); + int64_t numberOfAttemptedActivations = + numberOfAttemptedActivationsStr.ToInteger64(&rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + entry->mRegistration.numberOfAttemptedActivations() = + numberOfAttemptedActivations; + nsAutoCString isRegistrationBrokenStr; + GET_LINE(isRegistrationBrokenStr); + int64_t isBroken = isRegistrationBrokenStr.ToInteger64(&rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + entry->mRegistration.isBroken() = (isBroken != 0); + nsAutoCString cacheAPIIdStr; + GET_LINE(cacheAPIIdStr); + int64_t cacheAPIId = cacheAPIIdStr.ToInteger64(&rv); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + entry->mRegistration.cacheAPIId() = cacheAPIId; + + [[fallthrough]]; + } + + case 10: + [[fallthrough]]; + case 9: { rv = CreatePrincipalInfo(lineInputStream, entry->mRegistration); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -705,6 +733,10 @@ nsresult ServiceWorkerRegistrar::ReadData() { GET_LINE(entry->mRegistration.navigationPreloadState().headerValue()); + // expando was introcuded in version 10 + // but block was placed in version 9, since + // the expando is placed at the end of data + // and we cannot read it in case 10 block if (version >= 10) { nsAutoCString expandoCountStr; GET_LINE(expandoCountStr); @@ -730,47 +762,6 @@ nsresult ServiceWorkerRegistrar::ReadData() { } } - if (version >= 11) { - nsAutoCString numberOfAttemptedActivationsStr; - GET_LINE(numberOfAttemptedActivationsStr); - int64_t numberOfAttemptedActivations = - numberOfAttemptedActivationsStr.ToInteger64(&rv); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - entry->mRegistration.numberOfAttemptedActivations() = - numberOfAttemptedActivations; - nsAutoCString isRegistrationBrokenStr; - GET_LINE(isRegistrationBrokenStr); - int64_t isBroken = isRegistrationBrokenStr.ToInteger64(&rv); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - entry->mRegistration.isBroken() = (isBroken != 0); - nsAutoCString cacheAPIIdStr; - GET_LINE(cacheAPIIdStr); - int64_t cacheAPIId = cacheAPIIdStr.ToInteger64(&rv); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - entry->mRegistration.cacheAPIId() = cacheAPIId; - } - - // if we are on latest version, get service worker type - if (version == SERVICEWORKERREGISTRAR_VERSION) { - nsAutoCString serviceWorkerTypeStr; - GET_LINE(serviceWorkerTypeStr); - uint32_t serviceWorkerType = - serviceWorkerTypeStr.ToUnsignedInteger(&rv); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - if (serviceWorkerType > static_cast<uint32_t>(WorkerType::Module)) { - return NS_ERROR_INVALID_ARG; - } - entry->mRegistration.type() = - static_cast<WorkerType>(serviceWorkerType); - } break; } @@ -1455,6 +1446,16 @@ nsresult ServiceWorkerRegistrar::WriteData( buffer.Truncate(); + buffer.AppendInt(static_cast<int32_t>( + data.mRegistration.numberOfAttemptedActivations())); + buffer.Append('\n'); + + buffer.AppendInt(static_cast<int32_t>(data.mRegistration.isBroken())); + buffer.Append('\n'); + + buffer.AppendInt(static_cast<int32_t>(data.mRegistration.cacheAPIId())); + buffer.Append('\n'); + buffer.Append(suffix.get()); buffer.Append('\n'); @@ -1513,19 +1514,6 @@ nsresult ServiceWorkerRegistrar::WriteData( buffer.Append('\n'); } - buffer.AppendInt(static_cast<int32_t>( - data.mRegistration.numberOfAttemptedActivations())); - buffer.Append('\n'); - - buffer.AppendInt(static_cast<int32_t>(data.mRegistration.isBroken())); - buffer.Append('\n'); - - buffer.AppendInt(static_cast<int32_t>(data.mRegistration.cacheAPIId())); - buffer.Append('\n'); - - buffer.AppendInt(static_cast<uint32_t>(data.mRegistration.type())); - buffer.Append('\n'); - buffer.AppendLiteral(SERVICEWORKERREGISTRAR_TERMINATOR); buffer.Append('\n'); diff --git a/dom/serviceworkers/ServiceWorkerRegistrar.h b/dom/serviceworkers/ServiceWorkerRegistrar.h @@ -17,7 +17,7 @@ #include "nsTArray.h" #define SERVICEWORKERREGISTRAR_FILE u"serviceworker.txt" -#define SERVICEWORKERREGISTRAR_VERSION 12 +#define SERVICEWORKERREGISTRAR_VERSION 11 #define SERVICEWORKERREGISTRAR_TERMINATOR "#" #define SERVICEWORKERREGISTRAR_TRUE "true" #define SERVICEWORKERREGISTRAR_FALSE "false" diff --git a/dom/serviceworkers/ServiceWorkerRegistrarTypes.ipdlh b/dom/serviceworkers/ServiceWorkerRegistrarTypes.ipdlh @@ -5,13 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ include IPCNavigationPreloadState; -include "mozilla/dom/cache/IPCUtils.h"; -include "mozilla/dom/WorkerIPCUtils.h"; - -include IPCStream; - -using mozilla::dom::WorkerType - from "mozilla/dom/WorkerBinding.h"; include PBackgroundSharedTypes; namespace mozilla { @@ -23,8 +16,6 @@ struct ServiceWorkerRegistrationData bool isBroken; int64_t cacheAPIId; nsCString scope; - WorkerType type; - nsCString currentWorkerURL; bool currentWorkerHandlesFetch; diff --git a/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp b/dom/serviceworkers/ServiceWorkerRegistrationDescriptor.cpp @@ -30,8 +30,7 @@ ServiceWorkerRegistrationDescriptor::NewestInternal() const { ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, nsIPrincipal* aPrincipal, - const nsACString& aScope, WorkerType aType, - ServiceWorkerUpdateViaCache aUpdateViaCache) + const nsACString& aScope, ServiceWorkerUpdateViaCache aUpdateViaCache) : mData(MakeUnique<IPCServiceWorkerRegistrationDescriptor>()) { MOZ_ALWAYS_SUCCEEDS( PrincipalToPrincipalInfo(aPrincipal, &mData->principalInfo())); @@ -39,7 +38,6 @@ ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( mData->id() = aId; mData->version() = aVersion; mData->scope() = aScope; - mData->type() = aType; mData->updateViaCache() = aUpdateViaCache; mData->installing() = Nothing(); mData->waiting() = Nothing(); @@ -49,10 +47,10 @@ ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, const nsACString& aScope, - WorkerType aType, ServiceWorkerUpdateViaCache aUpdateViaCache) + ServiceWorkerUpdateViaCache aUpdateViaCache) : mData(MakeUnique<IPCServiceWorkerRegistrationDescriptor>( - aId, aVersion, aPrincipalInfo, nsCString(aScope), aType, - aUpdateViaCache, Nothing(), Nothing(), Nothing())) {} + aId, aVersion, aPrincipalInfo, nsCString(aScope), aUpdateViaCache, + Nothing(), Nothing(), Nothing())) {} ServiceWorkerRegistrationDescriptor::ServiceWorkerRegistrationDescriptor( const IPCServiceWorkerRegistrationDescriptor& aDescriptor) @@ -132,10 +130,6 @@ const nsCString& ServiceWorkerRegistrationDescriptor::Scope() const { return mData->scope(); } -WorkerType ServiceWorkerRegistrationDescriptor::Type() const { - return mData->type(); -} - Maybe<ServiceWorkerDescriptor> ServiceWorkerRegistrationDescriptor::GetInstalling() const { Maybe<ServiceWorkerDescriptor> result; @@ -242,10 +236,6 @@ 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 @@ -9,7 +9,6 @@ #include "mozilla/Maybe.h" #include "mozilla/UniquePtr.h" #include "mozilla/dom/ServiceWorkerDescriptor.h" -#include "mozilla/dom/WorkerBinding.h" namespace mozilla { @@ -37,14 +36,12 @@ class ServiceWorkerRegistrationDescriptor final { public: ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, nsIPrincipal* aPrincipal, - const nsACString& aScope, WorkerType aType, - ServiceWorkerUpdateViaCache aUpdateViaCache); + const nsACString& aScope, ServiceWorkerUpdateViaCache aUpdateViaCache); ServiceWorkerRegistrationDescriptor( uint64_t aId, uint64_t aVersion, const mozilla::ipc::PrincipalInfo& aPrincipalInfo, - const nsACString& aScope, WorkerType aType, - ServiceWorkerUpdateViaCache aUpdateViaCache); + const nsACString& aScope, ServiceWorkerUpdateViaCache aUpdateViaCache); explicit ServiceWorkerRegistrationDescriptor( const IPCServiceWorkerRegistrationDescriptor& aDescriptor); @@ -77,8 +74,6 @@ class ServiceWorkerRegistrationDescriptor final { const nsCString& Scope() const; - WorkerType Type() const; - Maybe<ServiceWorkerDescriptor> GetInstalling() const; Maybe<ServiceWorkerDescriptor> GetWaiting() const; @@ -93,8 +88,6 @@ 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 @@ -70,11 +70,11 @@ void ServiceWorkerRegistrationInfo::ClearAsCorrupt() { bool ServiceWorkerRegistrationInfo::IsCorrupt() const { return mCorrupt; } ServiceWorkerRegistrationInfo::ServiceWorkerRegistrationInfo( - const nsACString& aScope, WorkerType aType, nsIPrincipal* aPrincipal, + const nsACString& aScope, nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState&& aNavigationPreloadState) : mPrincipal(aPrincipal), - mDescriptor(GetNextId(), GetNextVersion(), aPrincipal, aScope, aType, + mDescriptor(GetNextId(), GetNextVersion(), aPrincipal, aScope, aUpdateViaCache), mControlledClientsCounter(0), mDelayMultiplier(0), @@ -130,10 +130,6 @@ const nsCString& ServiceWorkerRegistrationInfo::Scope() const { return mDescriptor.Scope(); } -WorkerType ServiceWorkerRegistrationInfo::Type() const { - return mDescriptor.Type(); -} - nsIPrincipal* ServiceWorkerRegistrationInfo::Principal() const { return mPrincipal; } @@ -452,11 +448,11 @@ bool ServiceWorkerRegistrationInfo::IsLastUpdateCheckTimeOverOneDay() const { } void ServiceWorkerRegistrationInfo::UpdateRegistrationState() { - UpdateRegistrationState(mDescriptor.UpdateViaCache(), mDescriptor.Type()); + UpdateRegistrationState(mDescriptor.UpdateViaCache()); } void ServiceWorkerRegistrationInfo::UpdateRegistrationState( - ServiceWorkerUpdateViaCache aUpdateViaCache, WorkerType aType) { + ServiceWorkerUpdateViaCache aUpdateViaCache) { MOZ_ASSERT(NS_IsMainThread()); TimeStamp oldest = TimeStamp::Now() - TimeDuration::FromSeconds(30); @@ -478,7 +474,6 @@ void ServiceWorkerRegistrationInfo::UpdateRegistrationState( mDescriptor.SetWorkers(mInstallingWorker, mWaitingWorker, mActiveWorker); mDescriptor.SetUpdateViaCache(aUpdateViaCache); - mDescriptor.SetWorkerType(aType); for (RefPtr<ServiceWorkerRegistrationListener> pinnedTarget : mInstanceList.ForwardRange()) { @@ -769,9 +764,9 @@ ServiceWorkerUpdateViaCache ServiceWorkerRegistrationInfo::GetUpdateViaCache() return mDescriptor.UpdateViaCache(); } -void ServiceWorkerRegistrationInfo::SetOptions( - ServiceWorkerUpdateViaCache aUpdateViaCache, WorkerType aType) { - UpdateRegistrationState(aUpdateViaCache, aType); +void ServiceWorkerRegistrationInfo::SetUpdateViaCache( + ServiceWorkerUpdateViaCache aUpdateViaCache) { + UpdateRegistrationState(aUpdateViaCache); } int64_t ServiceWorkerRegistrationInfo::GetLastUpdateTime() const { 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, WorkerType aType, nsIPrincipal* aPrincipal, + const nsACString& aScope, nsIPrincipal* aPrincipal, ServiceWorkerUpdateViaCache aUpdateViaCache, IPCNavigationPreloadState&& aNavigationPreloadState); @@ -100,8 +100,6 @@ class ServiceWorkerRegistrationInfo final const nsCString& Scope() const; - WorkerType Type() const; - nsIPrincipal* Principal() const; bool IsUnregistered() const; @@ -225,8 +223,7 @@ class ServiceWorkerRegistrationInfo final ServiceWorkerUpdateViaCache GetUpdateViaCache() const; - void SetOptions(ServiceWorkerUpdateViaCache aUpdateViaCache, - WorkerType aType); + void SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache); int64_t GetLastUpdateTime() const; @@ -260,8 +257,7 @@ class ServiceWorkerRegistrationInfo final // may get CC-ed. void UpdateRegistrationState(); - void UpdateRegistrationState(ServiceWorkerUpdateViaCache aUpdateViaCache, - WorkerType aType); + void UpdateRegistrationState(ServiceWorkerUpdateViaCache aUpdateViaCache); // Used by devtools to track changes to the properties of // *nsIServiceWorkerRegistrationInfo*. Note, this doesn't necessarily need to diff --git a/dom/serviceworkers/ServiceWorkerScriptCache.cpp b/dom/serviceworkers/ServiceWorkerScriptCache.cpp @@ -1080,14 +1080,13 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader, return rv; } - auto mimeTypeUTF16 = NS_ConvertUTF8toUTF16(mimeType); - if (mimeTypeUTF16.IsEmpty() || - !(nsContentUtils::IsJavascriptMIMEType(mimeTypeUTF16) || - nsContentUtils::IsJsonMimeType(mimeTypeUTF16))) { + if (mimeType.IsEmpty() || + !nsContentUtils::IsJavascriptMIMEType(NS_ConvertUTF8toUTF16(mimeType))) { ServiceWorkerManager::LocalizeAndReportToAllClients( mRegistration->Scope(), "ServiceWorkerRegisterMimeTypeError2", nsTArray<nsString>{NS_ConvertUTF8toUTF16(mRegistration->Scope()), - mimeTypeUTF16, NS_ConvertUTF8toUTF16(mURL)}); + NS_ConvertUTF8toUTF16(mimeType), + NS_ConvertUTF8toUTF16(mURL)}); rv = NS_ERROR_DOM_SECURITY_ERR; return rv; } diff --git a/dom/serviceworkers/ServiceWorkerUpdateJob.cpp b/dom/serviceworkers/ServiceWorkerUpdateJob.cpp @@ -418,9 +418,8 @@ void ServiceWorkerUpdateJob::ComparisonResult(nsresult aStatus, } RefPtr<ServiceWorkerInfo> sw = new ServiceWorkerInfo( - mRegistration->Principal(), mRegistration->Scope(), mRegistration->Type(), - mRegistration->Id(), mRegistration->Version(), mScriptSpec, aNewCacheName, - flags); + mRegistration->Principal(), mRegistration->Scope(), 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/serviceworkers/test/gtest/TestReadWrite.cpp b/dom/serviceworkers/test/gtest/TestReadWrite.cpp @@ -233,6 +233,12 @@ TEST(ServiceWorkerRegistrar, TestReadData) buffer.AppendInt(static_cast<uint32_t>(SERVICEWORKERREGISTRAR_VERSION)); buffer.Append("\n"); + buffer.AppendInt(0); + buffer.AppendLiteral("\n"); + buffer.AppendInt(0); + buffer.AppendLiteral("\n"); + buffer.AppendInt(0); + buffer.AppendLiteral("\n"); buffer.AppendLiteral("^inBrowser=1\n"); buffer.AppendLiteral("https://scope_0.org\ncurrentWorkerURL 0\n"); buffer.Append(SERVICEWORKERREGISTRAR_TRUE "\n"); @@ -251,16 +257,14 @@ TEST(ServiceWorkerRegistrar, TestReadData) buffer.AppendLiteral("true\n"); buffer.AppendInt(0); buffer.AppendLiteral("\n"); + buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n"); + buffer.AppendInt(0); buffer.AppendLiteral("\n"); buffer.AppendInt(0); buffer.AppendLiteral("\n"); buffer.AppendInt(0); buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); - buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n"); - buffer.AppendLiteral("\n"); buffer.AppendLiteral("https://scope_1.org\ncurrentWorkerURL 1\n"); buffer.Append(SERVICEWORKERREGISTRAR_FALSE "\n"); @@ -279,14 +283,6 @@ TEST(ServiceWorkerRegistrar, TestReadData) buffer.AppendLiteral("false\n"); buffer.AppendInt(0); buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n"); ASSERT_TRUE(CreateFile(buffer)) @@ -1026,7 +1022,6 @@ TEST(ServiceWorkerRegistrar, TestDedupeWrite) ServiceWorkerRegistrationData reg; reg.scope() = "https://scope_write.dedupe"_ns; - reg.type() = WorkerType::Classic; reg.currentWorkerURL() = nsPrintfCString("currentWorkerURL write %d", i); reg.currentWorkerHandlesFetch() = true; reg.cacheName() = @@ -1091,6 +1086,12 @@ TEST(ServiceWorkerRegistrar, TestLoadHandler) buffer.AppendInt(static_cast<uint32_t>(SERVICEWORKERREGISTRAR_VERSION)); buffer.Append("\n"); + buffer.AppendInt(0); + buffer.AppendLiteral("\n"); + buffer.AppendInt(0); + buffer.AppendLiteral("\n"); + buffer.AppendInt(0); + buffer.AppendLiteral("\n"); buffer.AppendLiteral("^inBrowser=1\n"); buffer.AppendLiteral("https://scope_0.org\ncurrentWorkerURL 0\n"); buffer.Append(SERVICEWORKERREGISTRAR_TRUE "\n"); @@ -1113,14 +1114,6 @@ TEST(ServiceWorkerRegistrar, TestLoadHandler) buffer.AppendLiteral("hello world!\n"); buffer.AppendLiteral("handler_test2\n"); buffer.AppendLiteral("hello\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); - buffer.AppendInt(0); - buffer.AppendLiteral("\n"); buffer.Append(SERVICEWORKERREGISTRAR_TERMINATOR "\n"); ASSERT_TRUE(CreateFile(buffer)) diff --git a/dom/webidl/ServiceWorkerContainer.webidl b/dom/webidl/ServiceWorkerContainer.webidl @@ -37,6 +37,5 @@ interface ServiceWorkerContainer : EventTarget { dictionary RegistrationOptions { USVString scope; - WorkerType type = "classic"; ServiceWorkerUpdateViaCache updateViaCache = "imports"; }; diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp @@ -1146,11 +1146,6 @@ 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; } diff --git a/dom/workers/loader/NetworkLoadHandler.cpp b/dom/workers/loader/NetworkLoadHandler.cpp @@ -309,23 +309,19 @@ nsresult NetworkLoadHandler::PrepareForRequest(nsIRequest* aRequest) { nsAutoCString mimeType; channel->GetContentType(mimeType); - auto mimeTypeUTF16 = NS_ConvertUTF8toUTF16(mimeType); - if (!nsContentUtils::IsJavascriptMIMEType(mimeTypeUTF16)) { - // JSON is allowed as a non-toplevel. - if (loadContext->IsTopLevel() || - !nsContentUtils::IsJsonMimeType(mimeTypeUTF16)) { - const nsCString& scope = mWorkerRef->Private() - ->GetServiceWorkerRegistrationDescriptor() - .Scope(); - - ServiceWorkerManager::LocalizeAndReportToAllClients( - scope, "ServiceWorkerRegisterMimeTypeError2", - nsTArray<nsString>{ - NS_ConvertUTF8toUTF16(scope), NS_ConvertUTF8toUTF16(mimeType), - NS_ConvertUTF8toUTF16(loadContext->mRequest->mURL)}); - - return NS_ERROR_DOM_NETWORK_ERR; - } + if (!nsContentUtils::IsJavascriptMIMEType( + NS_ConvertUTF8toUTF16(mimeType))) { + const nsCString& scope = mWorkerRef->Private() + ->GetServiceWorkerRegistrationDescriptor() + .Scope(); + + ServiceWorkerManager::LocalizeAndReportToAllClients( + scope, "ServiceWorkerRegisterMimeTypeError2", + nsTArray<nsString>{ + NS_ConvertUTF8toUTF16(scope), NS_ConvertUTF8toUTF16(mimeType), + NS_ConvertUTF8toUTF16(loadContext->mRequest->mURL)}); + + return NS_ERROR_DOM_NETWORK_ERR; } } diff --git a/dom/workers/loader/WorkerModuleLoader.cpp b/dom/workers/loader/WorkerModuleLoader.cpp @@ -128,11 +128,6 @@ bool WorkerModuleLoader::IsDynamicImportSupported() { return !workerPrivate->IsServiceWorker(); } -bool WorkerModuleLoader::IsForServiceWorker() const { - WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); - return workerPrivate && workerPrivate->IsServiceWorker(); -} - bool WorkerModuleLoader::CanStartLoad(ModuleLoadRequest* aRequest, nsresult* aRvOut) { return true; diff --git a/dom/workers/loader/WorkerModuleLoader.h b/dom/workers/loader/WorkerModuleLoader.h @@ -98,8 +98,6 @@ class WorkerModuleLoader : public JS::loader::ModuleLoaderBase { return aModuleType != JS::ModuleType::Unknown && aModuleType != JS::ModuleType::CSS; } - - virtual bool IsForServiceWorker() const override; }; } // namespace mozilla::dom::workerinternals::loader diff --git a/js/loader/ModuleLoaderBase.cpp b/js/loader/ModuleLoaderBase.cpp @@ -1474,14 +1474,7 @@ nsresult ModuleLoaderBase::EvaluateModule(ModuleLoadRequest* aRequest) { mozilla::dom::AutoEntryScript aes(mGlobalObject, "EvaluateModule", NS_IsMainThread()); - // We would like to handle any evaluation errors synchronously for service - // workers immediately such that if we are performing service worker - // registration we can fail it right away rather than having it fail later on - // an event loop turn which might be too late and the registration process - // would have succeeded by then. - return EvaluateModuleInContext( - aes.cx(), aRequest, - IsForServiceWorker() ? ThrowModuleErrorsSync : ReportModuleErrorsAsync); + return EvaluateModuleInContext(aes.cx(), aRequest, ReportModuleErrorsAsync); } nsresult ModuleLoaderBase::EvaluateModuleInContext( @@ -1557,13 +1550,6 @@ nsresult ModuleLoaderBase::EvaluateModuleInContext( // If the promise is rejected, the value is unwrapped from the promise value. if (!ThrowOnModuleEvaluationFailure(aCx, evaluationPromise, errorBehaviour)) { LOG(("ScriptLoadRequest (%p): evaluation failed on throw", aRequest)); - - if (IsForServiceWorker()) { - // If this module eval is being done for service workers, then we would - // like to throw/return right from here, such that if we are in - // registration phase, we can fail it synchronously right away. - return NS_ERROR_ABORT; - } } // TODO: Bug 1973321: Prepare Bytecode encoding for dynamic import diff --git a/js/loader/ModuleLoaderBase.h b/js/loader/ModuleLoaderBase.h @@ -333,8 +333,6 @@ class ModuleLoaderBase : public nsISupports { virtual bool IsDynamicImportSupported() { return true; } - virtual bool IsForServiceWorker() const { return false; } - // Called when dynamic import started successfully. virtual void OnDynamicImportStarted(ModuleLoadRequest* aRequest) {} diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp @@ -3037,14 +3037,6 @@ nsresult EnsureMIMEOfScript(HttpBaseChannel* aChannel, nsIURI* aURI, return NS_OK; } - if (nsContentUtils::IsJsonMimeType(typeString)) { - // script and json are both allowed - glean::http::script_block_incorrect_mime - .EnumGet(glean::http::ScriptBlockIncorrectMimeLabel::eTextJson) - .Add(); - return NS_OK; - } - switch (aLoadInfo->InternalContentPolicyType()) { case nsIContentPolicy::TYPE_SCRIPT: case nsIContentPolicy::TYPE_INTERNAL_SCRIPT: @@ -3264,8 +3256,7 @@ void WarnWrongMIMEOfScript(HttpBaseChannel* aChannel, nsIURI* aURI, aResponseHead->ContentType(contentType); NS_ConvertUTF8toUTF16 typeString(contentType); - if (nsContentUtils::IsJavascriptMIMEType(typeString) || - nsContentUtils::IsJsonMimeType(typeString)) { + if (nsContentUtils::IsJavascriptMIMEType(typeString)) { return; } diff --git a/testing/web-platform/meta/html/cross-origin-embedder-policy/reflection-credentialless.tentative.https.any.js.ini b/testing/web-platform/meta/html/cross-origin-embedder-policy/reflection-credentialless.tentative.https.any.js.ini @@ -24,5 +24,4 @@ [reflection-credentialless.tentative.https.any.serviceworker-module.html] - [reflection-credentialless] - expected: FAIL + expected: ERROR diff --git a/testing/web-platform/meta/html/cross-origin-embedder-policy/reflection-require-corp.tentative.https.any.js.ini b/testing/web-platform/meta/html/cross-origin-embedder-policy/reflection-require-corp.tentative.https.any.js.ini @@ -31,5 +31,4 @@ [reflection-require-corp.tentative.https.any.serviceworker-module.html] - [reflection-require-corp] - expected: FAIL + expected: ERROR diff --git a/testing/web-platform/meta/html/cross-origin-embedder-policy/reflection-unsafe-none.tentative.https.any.js.ini b/testing/web-platform/meta/html/cross-origin-embedder-policy/reflection-unsafe-none.tentative.https.any.js.ini @@ -26,5 +26,4 @@ [reflection-unsafe-none.tentative.https.any.serviceworker-module.html] - [reflection-unsafe-none] - expected: FAIL + expected: ERROR diff --git a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https.html.ini b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/json-module/json-module-service-worker-test.https.html.ini @@ -1,4 +1,3 @@ [json-module-service-worker-test.https.html] - # JSON module as a top-level is not throwing error, could be because of async script evaluation - [Trying to register a service worker with a top-level JSON Module should fail] - expected: FAIL -\ No newline at end of file + [Javascript importing JSON Module should load within the context of a service worker] + expected: FAIL diff --git a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-object.any.js.ini b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-object.any.js.ini @@ -0,0 +1,2 @@ +[import-meta-object.any.serviceworker-module.html] + expected: ERROR diff --git a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve.any.js.ini b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-resolve.any.js.ini @@ -4,3 +4,8 @@ if not fission and (os == "linux"): CRASH [import-meta-resolve.any.sharedworker-module.html] + +[import-meta-resolve.any.serviceworker-module.html] + expected: + if tsan: TIMEOUT + ERROR diff --git a/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-url.any.js.ini b/testing/web-platform/meta/html/semantics/scripting-1/the-script-element/module/import-meta/import-meta-url.any.js.ini @@ -11,6 +11,4 @@ if (os == "android") and not debug: [OK, CRASH] [import-meta-url.any.serviceworker-module.html] - expected: - if (os == "mac") and not debug: [OK, CRASH] - if (os == "android") and not debug: [OK, CRASH] + expected: ERROR diff --git a/testing/web-platform/meta/infrastructure/server/context.any.js.ini b/testing/web-platform/meta/infrastructure/server/context.any.js.ini @@ -1,8 +1,7 @@ [context.any.sharedworker-module.html] [context.any.serviceworker-module.html] - expected: - if (os == "android") and not debug: [OK, ERROR] + expected: ERROR [context.any.worker.html] expected: diff --git a/testing/web-platform/meta/service-workers/service-worker/no-dynamic-import-in-module.any.js.ini b/testing/web-platform/meta/service-workers/service-worker/no-dynamic-import-in-module.any.js.ini @@ -0,0 +1,4 @@ +[no-dynamic-import-in-module.any.serviceworker-module.html] + expected: + if (os == "android") and fission: [ERROR, TIMEOUT] + ERROR diff --git a/testing/web-platform/meta/service-workers/service-worker/registration-scope-module-static-import.https.html.ini b/testing/web-platform/meta/service-workers/service-worker/registration-scope-module-static-import.https.html.ini @@ -0,0 +1,9 @@ +[registration-scope-module-static-import.https.html] + [static imports redirecting to outside path restriction should be allowed] + expected: FAIL + + [static imports to outside path restriction should be allowed] + expected: FAIL + + [imported-module-script.js works when used as top-level] + expected: FAIL diff --git a/testing/web-platform/meta/service-workers/service-worker/registration-script-module.https.html.ini b/testing/web-platform/meta/service-workers/service-worker/registration-script-module.https.html.ini @@ -3,4 +3,4 @@ if (os == "mac") and not debug: [OK, TIMEOUT] [Registering script including caught exception] expected: - if (os == "mac") and not debug: [PASS, TIMEOUT] -\ No newline at end of file + if (os == "mac") and not debug: [PASS, TIMEOUT] diff --git a/testing/web-platform/meta/service-workers/service-worker/registration-script.https.html.ini b/testing/web-platform/meta/service-workers/service-worker/registration-script.https.html.ini @@ -17,7 +17,7 @@ expected: if (os == "android") and not debug: [PASS, TIMEOUT] - [Registering script including undefined error: classic] + [Registering script including undefined error] expected: if (os == "android") and not debug: [PASS, NOTRUN] @@ -25,6 +25,6 @@ expected: if (os == "android") and not debug: [PASS, NOTRUN] - [Registering script including uncaught exception: classic] + [Registering script including uncaught exception] expected: if (os == "android") and not debug: [PASS, NOTRUN] diff --git a/testing/web-platform/meta/service-workers/service-worker/update-bytecheck-cors-import.https.html.ini b/testing/web-platform/meta/service-workers/service-worker/update-bytecheck-cors-import.https.html.ini @@ -1,3 +1,14 @@ [update-bytecheck-cors-import.https.html] expected: if (os == "android") and debug: [OK, ERROR] + [Test module script(main: default, imported: default)] + expected: FAIL + + [Test module script(main: default, imported: time)] + expected: FAIL + + [Test module script(main: time, imported: default)] + expected: FAIL + + [Test module script(main: time, imported: time)] + expected: FAIL diff --git a/testing/web-platform/meta/service-workers/service-worker/update-bytecheck.https.html.ini b/testing/web-platform/meta/service-workers/service-worker/update-bytecheck.https.html.ini @@ -2,10 +2,17 @@ max-asserts: 2 expected: if (os == "android") and debug: [OK, ERROR] + [Test module script(main: default, imported: default)] + expected: FAIL + + [Test module script(main: default, imported: time)] + expected: FAIL [Test module script(main: time, imported: default)] - expected: - if (processor == "x86") and not debug: [PASS, FAIL] + expected: FAIL + + [Test module script(main: time, imported: time)] + expected: FAIL [Test(main: time, imported: default)] expected: diff --git a/testing/web-platform/meta/service-workers/service-worker/update-registration-with-type.https.html.ini b/testing/web-platform/meta/service-workers/service-worker/update-registration-with-type.https.html.ini @@ -1,4 +1,10 @@ [update-registration-with-type.https.html] + [Update the registration with a different script type (module => classic).] + expected: FAIL + + [Update the registration with a different script type (classic => module).] + expected: FAIL + [Update the registration with a different script type (classic => module) and with a same main script. Expect evaluation failed.] expected: FAIL diff --git a/testing/web-platform/tests/infrastructure/metadata/infrastructure/server/context.any.js.ini b/testing/web-platform/tests/infrastructure/metadata/infrastructure/server/context.any.js.ini @@ -4,9 +4,9 @@ if product == "epiphany" or product == "webkit": FAIL # https://bugs.webkit.org/show_bug.cgi?id=200815 [context.any.serviceworker-module.html] - [context] - expected: - if product == "epiphany" or product == "webkit": FAIL # https://bugs.webkit.org/show_bug.cgi?id=200815 + expected: + if product == "firefox": ERROR + if product == "firefox_android": ERROR [context.any.worker-module.html] diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/registration-tests-script.js b/testing/web-platform/tests/service-workers/service-worker/resources/registration-tests-script.js @@ -30,21 +30,21 @@ function registration_tests_script(register_method, type) { promise_test(function(t) { var script = 'resources/malformed-worker.py?undefined-error'; - var scope = `resources/scope/undefined-error/${type}`; + var scope = 'resources/scope/undefined-error'; return promise_rejects_js(t, TypeError, register_method(script, {scope: scope}), 'Registration of script including undefined error should fail.'); - }, `Registering script including undefined error: ${type}`); + }, 'Registering script including undefined error'); promise_test(function(t) { var script = 'resources/malformed-worker.py?uncaught-exception'; - var scope = `resources/scope/uncaught-exception/${type}`; + var scope = 'resources/scope/uncaught-exception'; return promise_rejects_js(t, TypeError, register_method(script, {scope: scope}), 'Registration of script including uncaught exception should fail.'); - }, `Registering script including uncaught exception: ${type}`); + }, 'Registering script including uncaught exception'); if (type === 'classic') { promise_test(function(t) {