Bug 1784476 - Move ClientInfo to WorkerLoadContext; r=asuth

Previously, we had the client info for main scripts on the ScriptLoadInfo, and in the ScriptLoader
for non-main scripts (ImportScripts case). This was a bit confusing, so I moved it all to the ScriptLoader as in the
importScripts case, it is always recreated with each new load. However, for modules this is not
true. In order to make it persistant for main scripts and modules, as well as ensure that it has the
correct data, it should always live on the WorkerLoadContext.

Differential Revision: https://phabricator.services.mozilla.com/D147317
This commit is contained in:
Yulia Startsev 2022-08-24 13:38:34 +00:00
Родитель 24c8e12590
Коммит e48cee9f1d
4 изменённых файлов: 18 добавлений и 11 удалений

Просмотреть файл

@ -452,13 +452,15 @@ WorkerScriptLoader::WorkerScriptLoader(
nsIGlobalObject* global = GetGlobal();
mClientInfo = global->GetClientInfo();
Maybe<ClientInfo> clientInfo = global->GetClientInfo();
mController = global->GetController();
for (const nsString& aScriptURL : aScriptURLs) {
WorkerLoadContext::Kind kind =
WorkerLoadContext::GetKind(aIsMainScript, IsDebuggerScript());
RefPtr<WorkerLoadContext> loadContext = new WorkerLoadContext(kind);
RefPtr<WorkerLoadContext> loadContext =
new WorkerLoadContext(kind, clientInfo);
// Create ScriptLoadRequests for this WorkerScriptLoader
ReferrerPolicy aReferrerPolicy = mWorkerRef->Private()->GetReferrerPolicy();
@ -782,9 +784,10 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadRequest* aRequest) {
rv = ChannelFromScriptURL(
principal, parentDoc, mWorkerRef->Private(), loadGroup, ios, secMan,
aRequest->mURI, mClientInfo, mController, loadContext->IsTopLevel(),
mWorkerScriptType, mWorkerRef->Private()->ContentPolicyType(),
loadFlags, mWorkerRef->Private()->CookieJarSettings(), referrerInfo,
aRequest->mURI, loadContext->mClientInfo, mController,
loadContext->IsTopLevel(), mWorkerScriptType,
mWorkerRef->Private()->ContentPolicyType(), loadFlags,
mWorkerRef->Private()->CookieJarSettings(), referrerInfo,
getter_AddRefs(channel));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -816,7 +819,7 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadRequest* aRequest) {
}
if (loadContext->IsTopLevel()) {
MOZ_DIAGNOSTIC_ASSERT(mClientInfo.isSome());
MOZ_DIAGNOSTIC_ASSERT(loadContext->mClientInfo.isSome());
// In order to get the correct foreign partitioned prinicpal, we need to
// set the `IsThirdPartyContextToTopWindow` to the channel's loadInfo.
@ -826,7 +829,9 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadRequest* aRequest) {
loadInfo->SetIsThirdPartyContextToTopWindow(
mWorkerRef->Private()->IsThirdPartyContextToTopWindow());
rv = AddClientChannelHelper(channel, std::move(mClientInfo),
Maybe<ClientInfo> clientInfo;
clientInfo.emplace(loadContext->mClientInfo.ref());
rv = AddClientChannelHelper(channel, std::move(clientInfo),
Maybe<ClientInfo>(),
mWorkerRef->Private()->HybridEventTarget());
if (NS_WARN_IF(NS_FAILED(rv))) {

Просмотреть файл

@ -134,7 +134,6 @@ class WorkerScriptLoader final : public nsINamed {
nsCOMPtr<nsIEventTarget> mSyncLoopTarget;
JS::loader::ScriptLoadRequestList mLoadingRequests;
JS::loader::ScriptLoadRequestList mLoadedRequests;
Maybe<ClientInfo> mClientInfo;
Maybe<ServiceWorkerDescriptor> mController;
WorkerScriptType mWorkerScriptType;
Maybe<nsresult> mCancelMainThread;

Просмотреть файл

@ -10,9 +10,11 @@
namespace mozilla {
namespace dom {
WorkerLoadContext::WorkerLoadContext(WorkerLoadContext::Kind aKind)
WorkerLoadContext::WorkerLoadContext(Kind aKind,
const Maybe<ClientInfo>& aClientInfo)
: JS::loader::LoadContextBase(JS::loader::ContextKind::Worker),
mKind(aKind){};
mKind(aKind),
mClientInfo(aClientInfo){};
void WorkerLoadContext::SetCacheCreator(
RefPtr<workerinternals::loader::CacheCreator> aCacheCreator) {

Просмотреть файл

@ -78,7 +78,7 @@ class WorkerLoadContext : public JS::loader::LoadContextBase {
DebuggerScript
};
explicit WorkerLoadContext(WorkerLoadContext::Kind aKind);
explicit WorkerLoadContext(Kind aKind, const Maybe<ClientInfo>& aClientInfo);
~WorkerLoadContext() = default;
@ -102,6 +102,7 @@ class WorkerLoadContext : public JS::loader::LoadContextBase {
nsresult mLoadResult = NS_ERROR_NOT_INITIALIZED;
bool mLoadingFinished = false;
Kind mKind;
Maybe<ClientInfo> mClientInfo;
/* These fields are only used by service workers */
/* TODO: Split out a ServiceWorkerLoadContext */