summaryrefslogtreecommitdiffstats
path: root/dom/workers/WorkerPrivate.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/workers/WorkerPrivate.cpp')
-rw-r--r--dom/workers/WorkerPrivate.cpp106
1 files changed, 63 insertions, 43 deletions
diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
index a8643981aa..df248acda4 100644
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -1443,8 +1443,8 @@ nsresult WorkerPrivate::SetCSPFromHeaderValues(
}
MOZ_ASSERT(selfURI, "need a self URI for CSP");
- rv = csp->SetRequestContextWithPrincipal(mLoadInfo.mPrincipal, selfURI,
- u""_ns, 0);
+ rv = csp->SetRequestContextWithPrincipal(mLoadInfo.mPrincipal, selfURI, ""_ns,
+ 0);
NS_ENSURE_SUCCESS(rv, rv);
csp->EnsureEventTarget(mMainThreadEventTarget);
@@ -1574,8 +1574,6 @@ nsresult WorkerPrivate::DispatchLockHeld(
MOZ_ASSERT_IF(aSyncLoopTarget, mThread);
if (mStatus == Dead || (!aSyncLoopTarget && ParentStatus() > Canceling)) {
- LOGV(("WorkerPrivate::DispatchLockHeld [%p] runnable %p, parent status: %u",
- this, runnable.get(), (uint8_t)(ParentStatus())));
NS_WARNING(
"A runnable was posted to a worker that is already shutting "
"down!");
@@ -1624,6 +1622,7 @@ nsresult WorkerPrivate::DispatchLockHeld(
}
if (NS_WARN_IF(NS_FAILED(rv))) {
+ LOGV(("WorkerPrivate::Dispatch Failed [%p]", this));
return rv;
}
@@ -2792,8 +2791,7 @@ nsresult WorkerPrivate::GetLoadInfo(
loadInfo.mOriginAttributes = aParent->GetOriginAttributes();
loadInfo.mServiceWorkersTestingInWindow =
aParent->ServiceWorkersTestingInWindow();
- loadInfo.mIsThirdPartyContextToTopWindow =
- aParent->IsThirdPartyContextToTopWindow();
+ loadInfo.mIsThirdPartyContext = aParent->IsThirdPartyContext();
loadInfo.mShouldResistFingerprinting = aParent->ShouldResistFingerprinting(
RFPTarget::IsAlwaysEnabledForPrecompute);
loadInfo.mOverriddenFingerprintingSettings =
@@ -2954,7 +2952,7 @@ nsresult WorkerPrivate::GetLoadInfo(
StorageAllowedForDocument(document) != StorageAccess::eAllow) {
loadInfo.mUsingStorageAccess = false;
}
- loadInfo.mIsThirdPartyContextToTopWindow =
+ loadInfo.mIsThirdPartyContext =
AntiTrackingUtils::IsThirdPartyWindow(globalWindow, nullptr);
loadInfo.mCookieJarSettings = document->CookieJarSettings();
if (loadInfo.mCookieJarSettings) {
@@ -3022,7 +3020,7 @@ nsresult WorkerPrivate::GetLoadInfo(
cookieJarSettings->Serialize(loadInfo.mCookieJarSettingsArgs);
loadInfo.mOriginAttributes = OriginAttributes();
- loadInfo.mIsThirdPartyContextToTopWindow = false;
+ loadInfo.mIsThirdPartyContext = false;
}
MOZ_ASSERT(loadInfo.mLoadingPrincipal);
@@ -3104,10 +3102,33 @@ void WorkerPrivate::OverrideLoadInfoLoadGroup(WorkerLoadInfo& aLoadInfo,
void WorkerPrivate::RunLoopNeverRan() {
LOG(WorkerLog(), ("WorkerPrivate::RunLoopNeverRan [%p]", this));
+ // RunLoopNeverRan is only called in WorkerThreadPrimaryRunnable::Run() to
+ // handle cases
+ // 1. Fail to get BackgroundChild for the worker thread or
+ // 2. Fail to initialize the worker's JS context
+ // However, mPreStartRunnables had already dispatched in
+ // WorkerThread::SetWorkerPrivateInWorkerThread() where beforing above jobs
+ // start. So we need to clean up these dispatched runnables for the worker
+ // thread.
+
+ auto data = mWorkerThreadAccessible.Access();
+ RefPtr<WorkerThread> thread;
{
MutexAutoLock lock(mMutex);
-
+ // WorkerPrivate::DoRunLoop() is never called, so CompileScriptRunnable
+ // should not execute yet. However, the Worker is going to "Dead", flip the
+ // mCancelBeforeWorkerScopeConstructed to true for the dispatched runnables
+ // to indicate runnables there is no valid WorkerGlobalScope for executing.
+ MOZ_ASSERT(!data->mCancelBeforeWorkerScopeConstructed);
+ data->mCancelBeforeWorkerScopeConstructed.Flip();
+ // Switch State to Dead
mStatus = Dead;
+ thread = mThread;
+ }
+
+ // Clear the dispatched mPreStartRunnables.
+ if (thread && NS_HasPendingEvents(thread)) {
+ NS_ProcessPendingEvents(nullptr);
}
// After mStatus is set to Dead there can be no more
@@ -3230,11 +3251,6 @@ void WorkerPrivate::DoRunLoop(JSContext* aCx) {
{
MutexAutoLock lock(mMutex);
-
- LOGV(
- ("WorkerPrivate::DoRunLoop [%p] mStatus %u before getting events"
- " to run",
- this, (uint8_t)mStatus));
if (checkFinalGCCC && currentStatus != mStatus) {
// Something moved our status while we were supposed to check for a
// potentially needed GC/CC. Just check again.
@@ -3270,6 +3286,25 @@ void WorkerPrivate::DoRunLoop(JSContext* aCx) {
currentStatus = mStatus;
}
+ // Status transitions to Closing/Canceling and there are no SyncLoops,
+ // set global start dying, disconnect EventTargetObjects and
+ // WebTaskScheduler.
+ // The Worker might switch to the "Killing" immediately then directly exits
+ // DoRunLoop(). Before exiting the DoRunLoop(), explicitly disconnecting the
+ // WorkerGlobalScope's EventTargetObject here would help to fail runnable
+ // dispatching when the Worker is in the status changing.
+ if (currentStatus >= Closing &&
+ !data->mPerformedShutdownAfterLastContentTaskExecuted) {
+ data->mPerformedShutdownAfterLastContentTaskExecuted.Flip();
+ if (data->mScope) {
+ data->mScope->NoteTerminating();
+ data->mScope->DisconnectGlobalTeardownObservers();
+ if (data->mScope->GetExistingScheduler()) {
+ data->mScope->GetExistingScheduler()->Disconnect();
+ }
+ }
+ }
+
// Transition from Canceling to Killing and exit this loop when:
// * All (non-weak) WorkerRefs have been released.
// * There are no runnables pending. This is intended to let same-thread
@@ -3335,21 +3370,6 @@ void WorkerPrivate::DoRunLoop(JSContext* aCx) {
}
}
- // Status transitions to Closing/Canceling and there are no SyncLoops,
- // set global start dying, disconnect EventTargetObjects and
- // WebTaskScheduler.
- if (currentStatus >= Closing &&
- !data->mPerformedShutdownAfterLastContentTaskExecuted) {
- data->mPerformedShutdownAfterLastContentTaskExecuted.Flip();
- if (data->mScope) {
- data->mScope->NoteTerminating();
- data->mScope->DisconnectGlobalTeardownObservers();
- if (data->mScope->GetExistingScheduler()) {
- data->mScope->GetExistingScheduler()->Disconnect();
- }
- }
- }
-
if (debuggerRunnablesPending || normalRunnablesPending) {
// Start the periodic GC timer if it is not already running.
SetGCTimerMode(PeriodicTimer);
@@ -4324,7 +4344,6 @@ void WorkerPrivate::AdjustNonblockingCCBackgroundActorCount(int32_t aCount) {
}
void WorkerPrivate::UpdateCCFlag(const CCFlag aFlag) {
- LOGV(("WorkerPrivate::UpdateCCFlag [%p]", this));
AssertIsOnWorkerThread();
auto data = mWorkerThreadAccessible.Access();
@@ -4984,17 +5003,6 @@ bool WorkerPrivate::NotifyInternal(WorkerStatus aStatus) {
MOZ_ASSERT_IF(aStatus == Killing,
mStatus == Canceling && mParentStatus == Canceling);
- if (aStatus >= Canceling) {
- MutexAutoUnlock unlock(mMutex);
- if (data->mScope) {
- if (aStatus == Canceling) {
- data->mScope->NoteTerminating();
- } else {
- data->mScope->NoteShuttingDown();
- }
- }
- }
-
mStatus = aStatus;
// Mark parent status as closing immediately to avoid new events being
@@ -5005,8 +5013,20 @@ bool WorkerPrivate::NotifyInternal(WorkerStatus aStatus) {
// Synchronize the mParentStatus with mStatus, such that event dispatching
// will fail in proper after WorkerPrivate gets into Killing status.
- if (aStatus == Killing) {
- mParentStatus = Killing;
+ if (aStatus >= Killing) {
+ mParentStatus = aStatus;
+ }
+ }
+
+ // Status transistion to "Canceling"/"Killing", mark the scope as dying when
+ // "Canceling," or shutdown the StorageManager when "Killing."
+ if (aStatus >= Canceling) {
+ if (data->mScope) {
+ if (aStatus == Canceling) {
+ data->mScope->NoteTerminating();
+ } else {
+ data->mScope->NoteShuttingDown();
+ }
}
}