зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1742438 - Part 2: Rename ScriptLoadInfo references from {a,m}LoadInfo to {a,m}Request; r=asuth
Doing the rename here so it doesn't make it confusing to review. Differential Revision: https://phabricator.services.mozilla.com/D146174
This commit is contained in:
Родитель
1ade00f949
Коммит
c7e0fc2f1f
|
@ -86,8 +86,8 @@ ScriptLoadInfo* AsWorkerRequest(JS::loader::ScriptLoadRequest* req) {
|
|||
return static_cast<ScriptLoadInfo*>(req);
|
||||
}
|
||||
|
||||
JS::loader::ScriptLoadRequest* AsScriptRequest(ScriptLoadInfo* aLoadInfo) {
|
||||
return static_cast<JS::loader::ScriptLoadRequest*>(aLoadInfo);
|
||||
JS::loader::ScriptLoadRequest* AsScriptRequest(ScriptLoadInfo* aRequest) {
|
||||
return static_cast<JS::loader::ScriptLoadRequest*>(aRequest);
|
||||
}
|
||||
|
||||
nsresult ConstructURI(const nsAString& aScriptURL, nsIURI* baseURI,
|
||||
|
@ -409,12 +409,12 @@ NS_IMPL_ISUPPORTS(ScriptLoaderRunnable, nsIRunnable, nsINamed)
|
|||
|
||||
class ScriptExecutorRunnable final : public MainThreadWorkerSyncRunnable {
|
||||
WorkerScriptLoader& mScriptLoader;
|
||||
ScriptLoadInfo* mLoadInfo;
|
||||
ScriptLoadInfo* mRequest;
|
||||
|
||||
public:
|
||||
ScriptExecutorRunnable(WorkerScriptLoader& aScriptLoader,
|
||||
nsIEventTarget* aSyncLoopTarget,
|
||||
ScriptLoadInfo* aLoadInfo);
|
||||
ScriptLoadInfo* aRequest);
|
||||
|
||||
private:
|
||||
~ScriptExecutorRunnable() = default;
|
||||
|
@ -533,38 +533,37 @@ nsIURI* WorkerScriptLoader::GetBaseURI() {
|
|||
return baseURI;
|
||||
}
|
||||
|
||||
void WorkerScriptLoader::LoadingFinished(ScriptLoadInfo* aLoadInfo,
|
||||
void WorkerScriptLoader::LoadingFinished(ScriptLoadInfo* aRequest,
|
||||
nsresult aRv) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
aLoadInfo->mLoadResult = aRv;
|
||||
aRequest->mLoadResult = aRv;
|
||||
|
||||
MOZ_ASSERT(!aLoadInfo->mLoadingFinished);
|
||||
aLoadInfo->mLoadingFinished = true;
|
||||
MOZ_ASSERT(!aRequest->mLoadingFinished);
|
||||
aRequest->mLoadingFinished = true;
|
||||
|
||||
if (IsMainWorkerScript() && NS_SUCCEEDED(aRv)) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(mWorkerPrivate->PrincipalURIMatchesScriptURL());
|
||||
}
|
||||
|
||||
MaybeExecuteFinishedScripts(aLoadInfo);
|
||||
MaybeExecuteFinishedScripts(aRequest);
|
||||
}
|
||||
|
||||
void WorkerScriptLoader::MaybeExecuteFinishedScripts(
|
||||
ScriptLoadInfo* aLoadInfo) {
|
||||
void WorkerScriptLoader::MaybeExecuteFinishedScripts(ScriptLoadInfo* aRequest) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
// We execute the last step if we don't have a pending operation with the
|
||||
// cache and the loading is completed.
|
||||
if (aLoadInfo->Finished()) {
|
||||
aLoadInfo->ClearCacheCreator();
|
||||
DispatchMaybeMoveToLoadedList(aLoadInfo);
|
||||
if (aRequest->Finished()) {
|
||||
aRequest->ClearCacheCreator();
|
||||
DispatchMaybeMoveToLoadedList(aRequest);
|
||||
}
|
||||
}
|
||||
|
||||
void WorkerScriptLoader::MaybeMoveToLoadedList(ScriptLoadInfo* aLoadInfo) {
|
||||
void WorkerScriptLoader::MaybeMoveToLoadedList(ScriptLoadInfo* aRequest) {
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
MOZ_ASSERT(!aLoadInfo->mExecutionScheduled);
|
||||
aLoadInfo->mExecutionScheduled = true;
|
||||
MOZ_ASSERT(!aRequest->mExecutionScheduled);
|
||||
aRequest->mExecutionScheduled = true;
|
||||
|
||||
while (!mLoadingRequests.isEmpty()) {
|
||||
ScriptLoadRequest* request = mLoadingRequests.getFirst();
|
||||
|
@ -633,11 +632,11 @@ bool WorkerScriptLoader::ProcessPendingRequests(JSContext* aCx) {
|
|||
return true;
|
||||
}
|
||||
|
||||
nsresult WorkerScriptLoader::OnStreamComplete(ScriptLoadInfo* aLoadInfo,
|
||||
nsresult WorkerScriptLoader::OnStreamComplete(ScriptLoadInfo* aRequest,
|
||||
nsresult aStatus) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
LoadingFinished(aLoadInfo, aStatus);
|
||||
LoadingFinished(aRequest, aStatus);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -707,13 +706,13 @@ nsresult WorkerScriptLoader::LoadScripts() {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aLoadInfo) {
|
||||
nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aRequest) {
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT_IF(IsMainWorkerScript(), !IsDebuggerScript());
|
||||
|
||||
// The URL passed to us for loading was invalid, stop loading at this point.
|
||||
if (aLoadInfo->mLoadResult != NS_ERROR_NOT_INITIALIZED) {
|
||||
return aLoadInfo->mLoadResult;
|
||||
if (aRequest->mLoadResult != NS_ERROR_NOT_INITIALIZED) {
|
||||
return aRequest->mLoadResult;
|
||||
}
|
||||
|
||||
WorkerPrivate* parentWorker = mWorkerPrivate->GetParent();
|
||||
|
@ -747,7 +746,7 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aLoadInfo) {
|
|||
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
|
||||
NS_ASSERTION(secMan, "This should never be null!");
|
||||
|
||||
nsresult& rv = aLoadInfo->mLoadResult;
|
||||
nsresult& rv = aRequest->mLoadResult;
|
||||
|
||||
nsLoadFlags loadFlags = mWorkerPrivate->GetLoadFlags();
|
||||
|
||||
|
@ -782,7 +781,7 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aLoadInfo) {
|
|||
->CloneWithNewPolicy(parentWorker->GetReferrerPolicy());
|
||||
}
|
||||
|
||||
ScriptLoadRequest* req = AsScriptRequest(aLoadInfo);
|
||||
ScriptLoadRequest* req = AsScriptRequest(aRequest);
|
||||
|
||||
rv = ChannelFromScriptURL(principal, parentDoc, mWorkerPrivate, loadGroup,
|
||||
ios, secMan, req->mURI, mClientInfo, mController,
|
||||
|
@ -802,7 +801,7 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aLoadInfo) {
|
|||
|
||||
// We need to know which index we're on in OnStreamComplete so we know
|
||||
// where to put the result.
|
||||
RefPtr<NetworkLoadHandler> listener = new NetworkLoadHandler(this, aLoadInfo);
|
||||
RefPtr<NetworkLoadHandler> listener = new NetworkLoadHandler(this, aRequest);
|
||||
|
||||
RefPtr<ScriptResponseHeaderProcessor> headerProcessor = nullptr;
|
||||
|
||||
|
@ -850,7 +849,7 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aLoadInfo) {
|
|||
channelLoadInfo->SetLoadingEmbedderPolicy(respectedCOEP);
|
||||
}
|
||||
|
||||
if (aLoadInfo->mCacheStatus != ScriptLoadInfo::ToBeCached) {
|
||||
if (aRequest->mCacheStatus != ScriptLoadInfo::ToBeCached) {
|
||||
rv = channel->AsyncOpen(loader);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
|
@ -859,10 +858,10 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aLoadInfo) {
|
|||
nsCOMPtr<nsIOutputStream> writer;
|
||||
|
||||
// In case we return early.
|
||||
aLoadInfo->mCacheStatus = ScriptLoadInfo::Cancel;
|
||||
aRequest->mCacheStatus = ScriptLoadInfo::Cancel;
|
||||
|
||||
rv = NS_NewPipe(
|
||||
getter_AddRefs(aLoadInfo->mCacheReadStream), getter_AddRefs(writer), 0,
|
||||
getter_AddRefs(aRequest->mCacheReadStream), getter_AddRefs(writer), 0,
|
||||
UINT32_MAX, // unlimited size to avoid writer WOULD_BLOCK case
|
||||
true, false); // non-blocking reader, blocking writer
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
|
@ -886,7 +885,7 @@ nsresult WorkerScriptLoader::LoadScript(ScriptLoadInfo* aLoadInfo) {
|
|||
}
|
||||
|
||||
void WorkerScriptLoader::DispatchMaybeMoveToLoadedList(
|
||||
ScriptLoadInfo* aLoadInfo) {
|
||||
ScriptLoadInfo* aRequest) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
if (IsMainWorkerScript()) {
|
||||
|
@ -894,24 +893,24 @@ void WorkerScriptLoader::DispatchMaybeMoveToLoadedList(
|
|||
}
|
||||
|
||||
RefPtr<ScriptExecutorRunnable> runnable =
|
||||
new ScriptExecutorRunnable(*this, mSyncLoopTarget, aLoadInfo);
|
||||
new ScriptExecutorRunnable(*this, mSyncLoopTarget, aRequest);
|
||||
if (!runnable->Dispatch()) {
|
||||
MOZ_ASSERT(false, "This should never fail!");
|
||||
}
|
||||
}
|
||||
|
||||
bool WorkerScriptLoader::EvaluateScript(JSContext* aCx,
|
||||
ScriptLoadInfo* aLoadInfo) {
|
||||
ScriptLoadInfo* aRequest) {
|
||||
mWorkerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
NS_ASSERTION(aLoadInfo->mExecutionScheduled, "Should be scheduled!");
|
||||
NS_ASSERTION(!aLoadInfo->mExecutionResult, "Should not have executed yet!");
|
||||
NS_ASSERTION(aRequest->mExecutionScheduled, "Should be scheduled!");
|
||||
NS_ASSERTION(!aRequest->mExecutionResult, "Should not have executed yet!");
|
||||
|
||||
MOZ_ASSERT(!mRv.Failed(), "Who failed it and why?");
|
||||
mRv.MightThrowJSException();
|
||||
if (NS_FAILED(aLoadInfo->mLoadResult)) {
|
||||
workerinternals::ReportLoadError(mRv, aLoadInfo->mLoadResult,
|
||||
aLoadInfo->mURL);
|
||||
if (NS_FAILED(aRequest->mLoadResult)) {
|
||||
workerinternals::ReportLoadError(mRv, aRequest->mLoadResult,
|
||||
aRequest->mURL);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -926,16 +925,16 @@ bool WorkerScriptLoader::EvaluateScript(JSContext* aCx,
|
|||
mWorkerPrivate->ExecutionReady();
|
||||
}
|
||||
|
||||
NS_ConvertUTF16toUTF8 filename(aLoadInfo->mURL);
|
||||
NS_ConvertUTF16toUTF8 filename(aRequest->mURL);
|
||||
|
||||
JS::CompileOptions options(aCx);
|
||||
options.setFileAndLine(filename.get(), 1).setNoScriptRval(true);
|
||||
|
||||
MOZ_ASSERT(aLoadInfo->mMutedErrorFlag.isSome());
|
||||
options.setMutedErrors(aLoadInfo->mMutedErrorFlag.valueOr(true));
|
||||
MOZ_ASSERT(aRequest->mMutedErrorFlag.isSome());
|
||||
options.setMutedErrors(aRequest->mMutedErrorFlag.valueOr(true));
|
||||
|
||||
if (aLoadInfo->mSourceMapURL) {
|
||||
options.setSourceMapURL(aLoadInfo->mSourceMapURL->get());
|
||||
if (aRequest->mSourceMapURL) {
|
||||
options.setSourceMapURL(aRequest->mSourceMapURL->get());
|
||||
}
|
||||
|
||||
// Our ErrorResult still shouldn't be a failure.
|
||||
|
@ -943,21 +942,21 @@ bool WorkerScriptLoader::EvaluateScript(JSContext* aCx,
|
|||
|
||||
// Transfer script length to a local variable, encoding-agnostically.
|
||||
size_t scriptLength = 0;
|
||||
std::swap(scriptLength, aLoadInfo->mScriptLength);
|
||||
std::swap(scriptLength, aRequest->mScriptLength);
|
||||
|
||||
// This transfers script data out of the active arm of |aLoadInfo->mScript|.
|
||||
// This transfers script data out of the active arm of |aRequest->mScript|.
|
||||
bool successfullyEvaluated =
|
||||
aLoadInfo->mScriptIsUTF8
|
||||
? EvaluateSourceBuffer(aCx, options, aLoadInfo->mScript.mUTF8,
|
||||
aRequest->mScriptIsUTF8
|
||||
? EvaluateSourceBuffer(aCx, options, aRequest->mScript.mUTF8,
|
||||
scriptLength)
|
||||
: EvaluateSourceBuffer(aCx, options, aLoadInfo->mScript.mUTF16,
|
||||
: EvaluateSourceBuffer(aCx, options, aRequest->mScript.mUTF16,
|
||||
scriptLength);
|
||||
MOZ_ASSERT(aLoadInfo->ScriptTextIsNull());
|
||||
MOZ_ASSERT(aRequest->ScriptTextIsNull());
|
||||
if (!successfullyEvaluated) {
|
||||
mRv.StealExceptionFromJSContext(aCx);
|
||||
return false;
|
||||
}
|
||||
aLoadInfo->mExecutionResult = true;
|
||||
aRequest->mExecutionResult = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1033,11 +1032,11 @@ NS_IMPL_ISUPPORTS(WorkerScriptLoader, nsINamed)
|
|||
|
||||
ScriptExecutorRunnable::ScriptExecutorRunnable(
|
||||
WorkerScriptLoader& aScriptLoader, nsIEventTarget* aSyncLoopTarget,
|
||||
ScriptLoadInfo* aLoadInfo)
|
||||
ScriptLoadInfo* aRequest)
|
||||
: MainThreadWorkerSyncRunnable(aScriptLoader.mWorkerPrivate,
|
||||
aSyncLoopTarget),
|
||||
mScriptLoader(aScriptLoader),
|
||||
mLoadInfo(aLoadInfo) {}
|
||||
mRequest(aRequest) {}
|
||||
|
||||
bool ScriptExecutorRunnable::IsDebuggerRunnable() const {
|
||||
// ScriptExecutorRunnable is used to execute both worker and debugger scripts.
|
||||
|
@ -1066,7 +1065,7 @@ bool ScriptExecutorRunnable::WorkerRun(JSContext* aCx,
|
|||
mScriptLoader.mSyncLoopTarget == mSyncLoopTarget,
|
||||
"Unexpected SyncLoopTarget. Check if the sync loop was closed early");
|
||||
|
||||
mScriptLoader.MaybeMoveToLoadedList(mLoadInfo);
|
||||
mScriptLoader.MaybeMoveToLoadedList(mRequest);
|
||||
return mScriptLoader.ProcessPendingRequests(aCx);
|
||||
}
|
||||
|
||||
|
|
|
@ -164,9 +164,9 @@ class WorkerScriptLoader final : public nsINamed {
|
|||
protected:
|
||||
nsIURI* GetBaseURI();
|
||||
|
||||
void MaybeExecuteFinishedScripts(ScriptLoadInfo* aLoadInfo);
|
||||
void MaybeExecuteFinishedScripts(ScriptLoadInfo* aRequest);
|
||||
|
||||
void MaybeMoveToLoadedList(ScriptLoadInfo* aLoadInfo);
|
||||
void MaybeMoveToLoadedList(ScriptLoadInfo* aRequest);
|
||||
|
||||
bool StoreCSP();
|
||||
|
||||
|
@ -176,7 +176,7 @@ class WorkerScriptLoader final : public nsINamed {
|
|||
return mLoadingRequests.isEmpty() && mLoadedRequests.isEmpty();
|
||||
}
|
||||
|
||||
nsresult OnStreamComplete(ScriptLoadInfo* aLoadInfo, nsresult aStatus);
|
||||
nsresult OnStreamComplete(ScriptLoadInfo* aRequest, nsresult aStatus);
|
||||
|
||||
// Are we loading the primary script, which is not a Debugger Script?
|
||||
bool IsMainWorkerScript() const {
|
||||
|
@ -200,7 +200,7 @@ class WorkerScriptLoader final : public nsINamed {
|
|||
|
||||
nsresult LoadScripts();
|
||||
|
||||
nsresult LoadScript(ScriptLoadInfo* aLoadInfo);
|
||||
nsresult LoadScript(ScriptLoadInfo* aRequest);
|
||||
|
||||
void ShutdownScriptLoader(JSContext* aCx, WorkerPrivate* aWorkerPrivate,
|
||||
bool aResult, bool aMutedError);
|
||||
|
@ -214,11 +214,11 @@ class WorkerScriptLoader final : public nsINamed {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void LoadingFinished(ScriptLoadInfo* aLoadInfo, nsresult aRv);
|
||||
void LoadingFinished(ScriptLoadInfo* aRequest, nsresult aRv);
|
||||
|
||||
void DispatchMaybeMoveToLoadedList(ScriptLoadInfo* aLoadInfo);
|
||||
void DispatchMaybeMoveToLoadedList(ScriptLoadInfo* aRequest);
|
||||
|
||||
bool EvaluateScript(JSContext* aCx, ScriptLoadInfo* aLoadInfo);
|
||||
bool EvaluateScript(JSContext* aCx, ScriptLoadInfo* aRequest);
|
||||
|
||||
void LogExceptionToConsole(JSContext* aCx, WorkerPrivate* aWorkerPrivate);
|
||||
};
|
||||
|
|
|
@ -44,15 +44,15 @@ void CachePromiseHandler::ResolvedCallback(JSContext* aCx,
|
|||
AssertIsOnMainThread();
|
||||
// May already have been canceled by CacheLoadHandler::Fail from
|
||||
// CancelMainThread.
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::WritingToCache ||
|
||||
mLoadInfo->mCacheStatus == ScriptLoadInfo::Cancel);
|
||||
MOZ_ASSERT_IF(mLoadInfo->mCacheStatus == ScriptLoadInfo::Cancel,
|
||||
!mLoadInfo->mCachePromise);
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::WritingToCache ||
|
||||
mRequest->mCacheStatus == ScriptLoadInfo::Cancel);
|
||||
MOZ_ASSERT_IF(mRequest->mCacheStatus == ScriptLoadInfo::Cancel,
|
||||
!mRequest->mCachePromise);
|
||||
|
||||
if (mLoadInfo->mCachePromise) {
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::Cached;
|
||||
mLoadInfo->mCachePromise = nullptr;
|
||||
mLoader->MaybeExecuteFinishedScripts(mLoadInfo);
|
||||
if (mRequest->mCachePromise) {
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::Cached;
|
||||
mRequest->mCachePromise = nullptr;
|
||||
mLoader->MaybeExecuteFinishedScripts(mRequest);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,15 +62,15 @@ void CachePromiseHandler::RejectedCallback(JSContext* aCx,
|
|||
AssertIsOnMainThread();
|
||||
// May already have been canceled by CacheLoadHandler::Fail from
|
||||
// CancelMainThread.
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::WritingToCache ||
|
||||
mLoadInfo->mCacheStatus == ScriptLoadInfo::Cancel);
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::Cancel;
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::WritingToCache ||
|
||||
mRequest->mCacheStatus == ScriptLoadInfo::Cancel);
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::Cancel;
|
||||
|
||||
mLoadInfo->mCachePromise = nullptr;
|
||||
mRequest->mCachePromise = nullptr;
|
||||
|
||||
// This will delete the cache object and will call LoadingFinished() with an
|
||||
// error for each ongoing operation.
|
||||
mLoadInfo->GetCacheCreator()->DeleteCache(NS_ERROR_FAILURE);
|
||||
mRequest->GetCacheCreator()->DeleteCache(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
CacheCreator::CacheCreator(WorkerPrivate* aWorkerPrivate)
|
||||
|
@ -214,10 +214,10 @@ void CacheCreator::DeleteCache(nsresult aReason) {
|
|||
}
|
||||
|
||||
CacheLoadHandler::CacheLoadHandler(WorkerPrivate* aWorkerPrivate,
|
||||
ScriptLoadInfo* aLoadInfo,
|
||||
ScriptLoadInfo* aRequest,
|
||||
bool aIsWorkerScript,
|
||||
WorkerScriptLoader* aLoader)
|
||||
: mLoadInfo(aLoadInfo),
|
||||
: mRequest(aRequest),
|
||||
mLoader(aLoader),
|
||||
mWorkerPrivate(aWorkerPrivate),
|
||||
mIsWorkerScript(aIsWorkerScript),
|
||||
|
@ -242,19 +242,19 @@ void CacheLoadHandler::Fail(nsresult aRv) {
|
|||
mFailed = true;
|
||||
|
||||
if (mPump) {
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::ReadingFromCache);
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::ReadingFromCache);
|
||||
mPump->Cancel(aRv);
|
||||
mPump = nullptr;
|
||||
}
|
||||
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::Cancel;
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::Cancel;
|
||||
|
||||
if (mLoadInfo->mCachePromise) {
|
||||
mLoadInfo->mCachePromise->MaybeReject(aRv);
|
||||
if (mRequest->mCachePromise) {
|
||||
mRequest->mCachePromise->MaybeReject(aRv);
|
||||
}
|
||||
mLoadInfo->mCachePromise = nullptr;
|
||||
mRequest->mCachePromise = nullptr;
|
||||
|
||||
mLoader->LoadingFinished(mLoadInfo, aRv);
|
||||
mLoader->LoadingFinished(mRequest, aRv);
|
||||
}
|
||||
|
||||
void CacheLoadHandler::Load(Cache* aCache) {
|
||||
|
@ -263,7 +263,7 @@ void CacheLoadHandler::Load(Cache* aCache) {
|
|||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsresult rv =
|
||||
NS_NewURI(getter_AddRefs(uri), mLoadInfo->mURL, nullptr, mBaseURI);
|
||||
NS_NewURI(getter_AddRefs(uri), mRequest->mURL, nullptr, mBaseURI);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
Fail(rv);
|
||||
return;
|
||||
|
@ -276,11 +276,11 @@ void CacheLoadHandler::Load(Cache* aCache) {
|
|||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mLoadInfo->mFullURL.IsEmpty());
|
||||
CopyUTF8toUTF16(spec, mLoadInfo->mFullURL);
|
||||
MOZ_ASSERT(mRequest->mFullURL.IsEmpty());
|
||||
CopyUTF8toUTF16(spec, mRequest->mFullURL);
|
||||
|
||||
mozilla::dom::RequestOrUSVString request;
|
||||
request.SetAsUSVString().ShareOrDependUpon(mLoadInfo->mFullURL);
|
||||
request.SetAsUSVString().ShareOrDependUpon(mRequest->mFullURL);
|
||||
|
||||
mozilla::dom::CacheQueryOptions params;
|
||||
|
||||
|
@ -303,7 +303,7 @@ void CacheLoadHandler::RejectedCallback(JSContext* aCx,
|
|||
JS::Handle<JS::Value> aValue,
|
||||
ErrorResult& aRv) {
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::Uncached);
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::Uncached);
|
||||
Fail(NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ void CacheLoadHandler::ResolvedCallback(JSContext* aCx,
|
|||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::Uncached);
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::Uncached);
|
||||
|
||||
nsresult rv;
|
||||
|
||||
|
@ -338,8 +338,8 @@ void CacheLoadHandler::ResolvedCallback(JSContext* aCx,
|
|||
return;
|
||||
}
|
||||
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::ToBeCached;
|
||||
rv = mLoader->LoadScript(mLoadInfo);
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::ToBeCached;
|
||||
rv = mLoader->LoadScript(mRequest);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
Fail(rv);
|
||||
}
|
||||
|
@ -387,11 +387,11 @@ void CacheLoadHandler::ResolvedCallback(JSContext* aCx,
|
|||
}
|
||||
|
||||
if (!inputStream) {
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::Cached;
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::Cached;
|
||||
nsresult rv = DataReceivedFromCache(
|
||||
(uint8_t*)"", 0, mChannelInfo, std::move(mPrincipalInfo),
|
||||
mCSPHeaderValue, mCSPReportOnlyHeaderValue, mReferrerPolicyHeaderValue);
|
||||
mLoader->OnStreamComplete(mLoadInfo, rv);
|
||||
mLoader->OnStreamComplete(mRequest, rv);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,7 @@ void CacheLoadHandler::ResolvedCallback(JSContext* aCx,
|
|||
}
|
||||
}
|
||||
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::ReadingFromCache;
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::ReadingFromCache;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -443,20 +443,20 @@ CacheLoadHandler::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
mPump = nullptr;
|
||||
|
||||
if (NS_FAILED(aStatus)) {
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::ReadingFromCache ||
|
||||
mLoadInfo->mCacheStatus == ScriptLoadInfo::Cancel);
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::ReadingFromCache ||
|
||||
mRequest->mCacheStatus == ScriptLoadInfo::Cancel);
|
||||
Fail(aStatus);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::ReadingFromCache);
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::Cached;
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::ReadingFromCache);
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::Cached;
|
||||
|
||||
MOZ_ASSERT(mPrincipalInfo);
|
||||
nsresult rv = DataReceivedFromCache(
|
||||
aString, aStringLen, mChannelInfo, std::move(mPrincipalInfo),
|
||||
mCSPHeaderValue, mCSPReportOnlyHeaderValue, mReferrerPolicyHeaderValue);
|
||||
return mLoader->OnStreamComplete(mLoadInfo, rv);
|
||||
return mLoader->OnStreamComplete(mRequest, rv);
|
||||
}
|
||||
|
||||
nsresult CacheLoadHandler::DataReceivedFromCache(
|
||||
|
@ -467,11 +467,11 @@ nsresult CacheLoadHandler::DataReceivedFromCache(
|
|||
const nsACString& aReferrerPolicyHeaderValue) {
|
||||
AssertIsOnMainThread();
|
||||
if (mLoader->IsCancelled()) {
|
||||
mLoadInfo->GetCacheCreator()->DeleteCache(mLoader->mCancelMainThread.ref());
|
||||
mRequest->GetCacheCreator()->DeleteCache(mLoader->mCancelMainThread.ref());
|
||||
return mLoader->mCancelMainThread.ref();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mLoadInfo->mCacheStatus == ScriptLoadInfo::Cached);
|
||||
MOZ_ASSERT(mRequest->mCacheStatus == ScriptLoadInfo::Cached);
|
||||
|
||||
auto responsePrincipalOrErr = PrincipalInfoToPrincipal(*aPrincipalInfo);
|
||||
MOZ_DIAGNOSTIC_ASSERT(responsePrincipalOrErr.isOk());
|
||||
|
@ -485,28 +485,28 @@ nsresult CacheLoadHandler::DataReceivedFromCache(
|
|||
|
||||
nsCOMPtr<nsIPrincipal> responsePrincipal = responsePrincipalOrErr.unwrap();
|
||||
|
||||
mLoadInfo->mMutedErrorFlag.emplace(!principal->Subsumes(responsePrincipal));
|
||||
mRequest->mMutedErrorFlag.emplace(!principal->Subsumes(responsePrincipal));
|
||||
|
||||
// May be null.
|
||||
Document* parentDoc = mWorkerPrivate->GetDocument();
|
||||
|
||||
MOZ_ASSERT(mLoadInfo->ScriptTextIsNull());
|
||||
MOZ_ASSERT(mRequest->ScriptTextIsNull());
|
||||
|
||||
nsresult rv;
|
||||
if (StaticPrefs::dom_worker_script_loader_utf8_parsing_enabled()) {
|
||||
mLoadInfo->InitUTF8Script();
|
||||
mRequest->InitUTF8Script();
|
||||
rv = ScriptLoader::ConvertToUTF8(nullptr, aString, aStringLen, u"UTF-8"_ns,
|
||||
parentDoc, mLoadInfo->mScript.mUTF8,
|
||||
mLoadInfo->mScriptLength);
|
||||
parentDoc, mRequest->mScript.mUTF8,
|
||||
mRequest->mScriptLength);
|
||||
} else {
|
||||
mLoadInfo->InitUTF16Script();
|
||||
mRequest->InitUTF16Script();
|
||||
rv = ScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen, u"UTF-8"_ns,
|
||||
parentDoc, mLoadInfo->mScript.mUTF16,
|
||||
mLoadInfo->mScriptLength);
|
||||
parentDoc, mRequest->mScript.mUTF16,
|
||||
mRequest->mScriptLength);
|
||||
}
|
||||
if (NS_SUCCEEDED(rv) && mLoader->IsMainWorkerScript()) {
|
||||
nsCOMPtr<nsIURI> finalURI;
|
||||
rv = NS_NewURI(getter_AddRefs(finalURI), mLoadInfo->mFullURL);
|
||||
rv = NS_NewURI(getter_AddRefs(finalURI), mRequest->mFullURL);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mWorkerPrivate->SetBaseURI(finalURI);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class CacheLoadHandler final : public PromiseNativeHandler,
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
|
||||
CacheLoadHandler(WorkerPrivate* aWorkerPrivate, ScriptLoadInfo* aLoadInfo,
|
||||
CacheLoadHandler(WorkerPrivate* aWorkerPrivate, ScriptLoadInfo* aRequest,
|
||||
bool aIsWorkerScript, WorkerScriptLoader* aLoader);
|
||||
|
||||
void Fail(nsresult aRv);
|
||||
|
@ -102,7 +102,7 @@ class CacheLoadHandler final : public PromiseNativeHandler,
|
|||
const nsACString& aReferrerPolicyHeaderValue);
|
||||
void DataReceived();
|
||||
|
||||
ScriptLoadInfo* mLoadInfo;
|
||||
ScriptLoadInfo* mRequest;
|
||||
const RefPtr<WorkerScriptLoader> mLoader;
|
||||
WorkerPrivate* const mWorkerPrivate;
|
||||
const bool mIsWorkerScript;
|
||||
|
@ -193,8 +193,8 @@ class CachePromiseHandler final : public PromiseNativeHandler {
|
|||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
CachePromiseHandler(WorkerScriptLoader* aLoader, ScriptLoadInfo* aLoadInfo)
|
||||
: mLoader(aLoader), mLoadInfo(aLoadInfo) {
|
||||
CachePromiseHandler(WorkerScriptLoader* aLoader, ScriptLoadInfo* aRequest)
|
||||
: mLoader(aLoader), mRequest(aRequest) {
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT(mLoader);
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ class CachePromiseHandler final : public PromiseNativeHandler {
|
|||
~CachePromiseHandler() { AssertIsOnMainThread(); }
|
||||
|
||||
RefPtr<WorkerScriptLoader> mLoader;
|
||||
ScriptLoadInfo* mLoadInfo;
|
||||
ScriptLoadInfo* mRequest;
|
||||
};
|
||||
|
||||
} // namespace workerinternals::loader
|
||||
|
|
|
@ -36,10 +36,10 @@ NS_IMPL_ISUPPORTS(NetworkLoadHandler, nsIStreamLoaderObserver,
|
|||
nsIRequestObserver)
|
||||
|
||||
NetworkLoadHandler::NetworkLoadHandler(WorkerScriptLoader* aLoader,
|
||||
ScriptLoadInfo* aLoadInfo)
|
||||
ScriptLoadInfo* aRequest)
|
||||
: mLoader(aLoader),
|
||||
mWorkerPrivate(aLoader->mWorkerPrivate),
|
||||
mLoadInfo(aLoadInfo) {
|
||||
mRequest(aRequest) {
|
||||
MOZ_ASSERT(mLoader);
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ NetworkLoadHandler::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
uint32_t aStringLen,
|
||||
const uint8_t* aString) {
|
||||
nsresult rv = DataReceivedFromNetwork(aLoader, aStatus, aStringLen, aString);
|
||||
return mLoader->OnStreamComplete(mLoadInfo, rv);
|
||||
return mLoader->OnStreamComplete(mRequest, rv);
|
||||
}
|
||||
|
||||
nsresult NetworkLoadHandler::DataReceivedFromNetwork(nsIStreamLoader* aLoader,
|
||||
|
@ -109,8 +109,8 @@ nsresult NetworkLoadHandler::DataReceivedFromNetwork(nsIStreamLoader* aLoader,
|
|||
// same-origin checks on them so we should be able to see their errors.
|
||||
// Note that for data: url, where we allow it through the same-origin check
|
||||
// but then give it a different origin.
|
||||
mLoadInfo->mMutedErrorFlag.emplace(!mLoader->IsMainWorkerScript() &&
|
||||
!principal->Subsumes(channelPrincipal));
|
||||
mRequest->mMutedErrorFlag.emplace(!mLoader->IsMainWorkerScript() &&
|
||||
!principal->Subsumes(channelPrincipal));
|
||||
|
||||
// Make sure we're not seeing the result of a 404 or something by checking
|
||||
// the 'requestSucceeded' attribute on the http channel.
|
||||
|
@ -137,7 +137,7 @@ nsresult NetworkLoadHandler::DataReceivedFromNetwork(nsIStreamLoader* aLoader,
|
|||
|
||||
nsAutoCString sourceMapURL;
|
||||
if (nsContentUtils::GetSourceMapURL(httpChannel, sourceMapURL)) {
|
||||
mLoadInfo->mSourceMapURL = Some(NS_ConvertUTF8toUTF16(sourceMapURL));
|
||||
mRequest->mSourceMapURL = Some(NS_ConvertUTF8toUTF16(sourceMapURL));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,22 +149,22 @@ nsresult NetworkLoadHandler::DataReceivedFromNetwork(nsIStreamLoader* aLoader,
|
|||
// Worker scripts are always decoded as UTF-8 per spec. Passing null for a
|
||||
// channel and UTF-8 for the hint will always interpret |aString| as UTF-8.
|
||||
if (StaticPrefs::dom_worker_script_loader_utf8_parsing_enabled()) {
|
||||
mLoadInfo->InitUTF8Script();
|
||||
mRequest->InitUTF8Script();
|
||||
rv = ScriptLoader::ConvertToUTF8(nullptr, aString, aStringLen, u"UTF-8"_ns,
|
||||
parentDoc, mLoadInfo->mScript.mUTF8,
|
||||
mLoadInfo->mScriptLength);
|
||||
parentDoc, mRequest->mScript.mUTF8,
|
||||
mRequest->mScriptLength);
|
||||
} else {
|
||||
mLoadInfo->InitUTF16Script();
|
||||
mRequest->InitUTF16Script();
|
||||
rv = ScriptLoader::ConvertToUTF16(nullptr, aString, aStringLen, u"UTF-8"_ns,
|
||||
parentDoc, mLoadInfo->mScript.mUTF16,
|
||||
mLoadInfo->mScriptLength);
|
||||
parentDoc, mRequest->mScript.mUTF16,
|
||||
mRequest->mScriptLength);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (mLoadInfo->ScriptTextIsNull()) {
|
||||
if (mLoadInfo->mScriptLength != 0) {
|
||||
if (mRequest->ScriptTextIsNull()) {
|
||||
if (mRequest->mScriptLength != 0) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ nsresult NetworkLoadHandler::DataReceivedFromNetwork(nsIStreamLoader* aLoader,
|
|||
if (!filename.IsEmpty()) {
|
||||
// This will help callers figure out what their script url resolved to
|
||||
// in case of errors.
|
||||
mLoadInfo->mURL.Assign(NS_ConvertUTF8toUTF16(filename));
|
||||
mRequest->mURL.Assign(NS_ConvertUTF8toUTF16(filename));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ nsresult NetworkLoadHandler::PrepareForRequest(nsIRequest* aRequest) {
|
|||
ServiceWorkerManager::LocalizeAndReportToAllClients(
|
||||
scope, "ServiceWorkerRegisterMimeTypeError2",
|
||||
nsTArray<nsString>{NS_ConvertUTF8toUTF16(scope),
|
||||
NS_ConvertUTF8toUTF16(mimeType), mLoadInfo->mURL});
|
||||
NS_ConvertUTF8toUTF16(mimeType), mRequest->mURL});
|
||||
|
||||
return NS_ERROR_DOM_NETWORK_ERR;
|
||||
}
|
||||
|
@ -304,11 +304,11 @@ nsresult NetworkLoadHandler::PrepareForRequest(nsIRequest* aRequest) {
|
|||
// We synthesize the result code, but its never exposed to content.
|
||||
SafeRefPtr<mozilla::dom::InternalResponse> ir =
|
||||
MakeSafeRefPtr<mozilla::dom::InternalResponse>(200, "OK"_ns);
|
||||
ir->SetBody(mLoadInfo->mCacheReadStream, InternalResponse::UNKNOWN_BODY_SIZE);
|
||||
ir->SetBody(mRequest->mCacheReadStream, InternalResponse::UNKNOWN_BODY_SIZE);
|
||||
|
||||
// Drop our reference to the stream now that we've passed it along, so it
|
||||
// doesn't hang around once the cache is done with it and keep data alive.
|
||||
mLoadInfo->mCacheReadStream = nullptr;
|
||||
mRequest->mCacheReadStream = nullptr;
|
||||
|
||||
// Set the channel info of the channel on the response so that it's
|
||||
// saved in the cache.
|
||||
|
@ -330,12 +330,12 @@ nsresult NetworkLoadHandler::PrepareForRequest(nsIRequest* aRequest) {
|
|||
ir->Headers()->FillResponseHeaders(channel);
|
||||
|
||||
RefPtr<mozilla::dom::Response> response = new mozilla::dom::Response(
|
||||
mLoadInfo->GetCacheCreator()->Global(), std::move(ir), nullptr);
|
||||
mRequest->GetCacheCreator()->Global(), std::move(ir), nullptr);
|
||||
|
||||
mozilla::dom::RequestOrUSVString request;
|
||||
|
||||
MOZ_ASSERT(!mLoadInfo->mFullURL.IsEmpty());
|
||||
request.SetAsUSVString().ShareOrDependUpon(mLoadInfo->mFullURL);
|
||||
MOZ_ASSERT(!mRequest->mFullURL.IsEmpty());
|
||||
request.SetAsUSVString().ShareOrDependUpon(mRequest->mFullURL);
|
||||
|
||||
// This JSContext will not end up executing JS code because here there are
|
||||
// no ReadableStreams involved.
|
||||
|
@ -343,7 +343,7 @@ nsresult NetworkLoadHandler::PrepareForRequest(nsIRequest* aRequest) {
|
|||
jsapi.Init();
|
||||
|
||||
ErrorResult error;
|
||||
RefPtr<Promise> cachePromise = mLoadInfo->GetCacheCreator()->Cache_()->Put(
|
||||
RefPtr<Promise> cachePromise = mRequest->GetCacheCreator()->Cache_()->Put(
|
||||
jsapi.cx(), request, *response, error);
|
||||
error.WouldReportJSException();
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
|
@ -351,11 +351,11 @@ nsresult NetworkLoadHandler::PrepareForRequest(nsIRequest* aRequest) {
|
|||
}
|
||||
|
||||
RefPtr<CachePromiseHandler> promiseHandler =
|
||||
new CachePromiseHandler(mLoader, mLoadInfo);
|
||||
new CachePromiseHandler(mLoader, mRequest);
|
||||
cachePromise->AppendNativeHandler(promiseHandler);
|
||||
|
||||
mLoadInfo->mCachePromise.swap(cachePromise);
|
||||
mLoadInfo->mCacheStatus = ScriptLoadInfo::WritingToCache;
|
||||
mRequest->mCachePromise.swap(cachePromise);
|
||||
mRequest->mCacheStatus = ScriptLoadInfo::WritingToCache;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class NetworkLoadHandler final : public nsIStreamLoaderObserver,
|
|||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NetworkLoadHandler(WorkerScriptLoader* aLoader, ScriptLoadInfo* aLoadInfo);
|
||||
NetworkLoadHandler(WorkerScriptLoader* aLoader, ScriptLoadInfo* aRequest);
|
||||
|
||||
NS_IMETHOD
|
||||
OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext,
|
||||
|
@ -67,7 +67,7 @@ class NetworkLoadHandler final : public nsIStreamLoaderObserver,
|
|||
|
||||
RefPtr<WorkerScriptLoader> mLoader;
|
||||
WorkerPrivate* const mWorkerPrivate;
|
||||
ScriptLoadInfo* mLoadInfo;
|
||||
ScriptLoadInfo* mRequest;
|
||||
};
|
||||
|
||||
} // namespace mozilla::dom::workerinternals::loader
|
||||
|
|
Загрузка…
Ссылка в новой задаче