Skip to content

Commit

Permalink
Bug 931249 - Patch 12 - Call LoadingFinished even if channel is not p…
Browse files Browse the repository at this point in the history
…resent. 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
  • Loading branch information
rmottola committed Jul 1, 2019
1 parent 33bf983 commit 2a868e4
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions dom/workers/ScriptLoader.cpp
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 2a868e4

Please sign in to comment.