diff --git a/dom/serviceworkers/ServiceWorkerScriptCache.cpp b/dom/serviceworkers/ServiceWorkerScriptCache.cpp index 00b69ebf45a0..239a50f553b0 100644 --- a/dom/serviceworkers/ServiceWorkerScriptCache.cpp +++ b/dom/serviceworkers/ServiceWorkerScriptCache.cpp @@ -693,6 +693,16 @@ nsresult CompareNetwork::Initialize(nsIPrincipal* aPrincipal, return rv; } + // Set the IsInThirdPartyContext for the channel's loadInfo according to the + // partitionKey of the principal. The worker is foreign if it's using + // partitioned principal, i.e. the partitionKey is not empty. In this case, + // we need to set the bit to the channel's loadInfo. + if (!aPrincipal->OriginAttributesRef().mPartitionKey.IsEmpty()) { + nsCOMPtr loadInfo = mChannel->LoadInfo(); + rv = loadInfo->SetIsInThirdPartyContext(true); + MOZ_ASSERT(NS_SUCCEEDED(rv)); + } + nsCOMPtr httpChannel = do_QueryInterface(mChannel); if (httpChannel) { // Spec says no redirects allowed for top-level SW scripts. diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index b841a6e35719..f2e00a173a69 100644 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -1025,6 +1025,18 @@ nsresult WorkerScriptLoader::LoadScript( if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } + + // Set the IsInThirdPartyContext for the channel's loadInfo according to the + // partitionKey of the principal. The worker is foreign if it's using + // partitioned principal, i.e. the partitionKey is not empty. In this case, + // we need to set the bit to the channel's loadInfo. + if (!principal->OriginAttributesRef().mPartitionKey.IsEmpty()) { + nsCOMPtr loadInfo = channel->LoadInfo(); + rv = loadInfo->SetIsInThirdPartyContext(true); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + } } // Associate any originating stack with the channel.