From 2a868e45a7d6d628e7da07d6bb621a93e192971d Mon Sep 17 00:00:00 2001 From: Riccardo Mottola Date: Mon, 1 Jul 2019 19:46:59 +0200 Subject: [PATCH] Bug 931249 - Patch 12 - Call LoadingFinished even if channel is not present. r=khuey If the failure was due to inability to create a channel (csp, other restrictions) we still want to mark the load as finished --- dom/workers/ScriptLoader.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/dom/workers/ScriptLoader.cpp b/dom/workers/ScriptLoader.cpp index 5f495ee9bd4..4b9f7c85423 100755 --- a/dom/workers/ScriptLoader.cpp +++ b/dom/workers/ScriptLoader.cpp @@ -531,7 +531,7 @@ class ScriptLoaderRunnable final : public WorkerFeature, // We execute the last step if we don't have a pending operation with the // cache and the loading is completed. - if (!mCanceledMainThread && loadInfo.Finished()) { + if (loadInfo.Finished()) { ExecuteFinishedScripts(); } } @@ -607,15 +607,26 @@ class ScriptLoaderRunnable final : public WorkerFeature, for (uint32_t index = 0; index < mLoadInfos.Length(); index++) { ScriptLoadInfo& loadInfo = mLoadInfos[index]; + // If promise or channel is non-null, there failures will lead to + // LoadingFinished being called. + bool callLoadingFinished = true; + if (loadInfo.mCachePromise) { MOZ_ASSERT(mWorkerPrivate->IsServiceWorker()); loadInfo.mCachePromise->MaybeReject(NS_BINDING_ABORTED); loadInfo.mCachePromise = nullptr; + callLoadingFinished = false; } - if (loadInfo.mChannel && - NS_FAILED(loadInfo.mChannel->Cancel(NS_BINDING_ABORTED))) { - NS_WARNING("Failed to cancel channel!"); + if (loadInfo.mChannel) { + if (NS_SUCCEEDED(loadInfo.mChannel->Cancel(NS_BINDING_ABORTED))) { + callLoadingFinished = false; + } else { + NS_WARNING("Failed to cancel channel!"); + } + } + + if (callLoadingFinished && !loadInfo.Finished()) { LoadingFinished(index, NS_BINDING_ABORTED); } } @@ -1080,8 +1091,10 @@ CachePromiseHandler::ResolvedCallback(JSContext* aCx, MOZ_ASSERT(mLoadInfo.mCacheStatus == ScriptLoadInfo::WritingToCache); mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached; - mLoadInfo.mCachePromise = nullptr; - mRunnable->MaybeExecuteFinishedScripts(mIndex); + if (mLoadInfo.mCachePromise) { + mLoadInfo.mCachePromise = nullptr; + mRunnable->MaybeExecuteFinishedScripts(mIndex); + } } void @@ -1232,6 +1245,12 @@ CacheScriptLoader::Fail(nsresult aRv) } mLoadInfo.mCacheStatus = ScriptLoadInfo::Cancel; + + // Stop if the load was aborted on the main thread. + if (mLoadInfo.Finished()) { + return; + } + mRunnable->LoadingFinished(mIndex, aRv); }