diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 1522e3d16620..71c5c64ed78d 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1777,6 +1777,7 @@ Loader::DoParseSheetServo(ServoStyleSheet* aSheet, // pending. BlockOnload(); RefPtr loadData = aLoadData; + nsCOMPtr target = DispatchTarget(); aSheet->ParseSheet( this, aUTF8.IsEmpty() ? NS_ConvertUTF16toUTF8(aUTF16) : aUTF8, @@ -1786,7 +1787,7 @@ Loader::DoParseSheetServo(ServoStyleSheet* aSheet, aLoadData, aLoadData->mLineNumber, GetCompatibilityMode() - )->Then(GetMainThreadSerialEventTarget(), __func__, + )->Then(target, __func__, [loadData](bool aDummy) { MOZ_ASSERT(NS_IsMainThread()); loadData->mIsBeingParsed = false; @@ -2761,6 +2762,20 @@ Loader::UnblockOnload(bool aFireSync) } } +already_AddRefed +Loader::DispatchTarget() +{ + nsCOMPtr target; + if (mDocument) { + target = mDocument->EventTargetFor(TaskCategory::Other); + } else if (mDocGroup) { + target = mDocGroup->EventTargetFor(TaskCategory::Other); + } else { + target = SystemGroup::EventTargetFor(TaskCategory::Other); + } + + return target.forget(); +} } // namespace css } // namespace mozilla diff --git a/layout/style/Loader.h b/layout/style/Loader.h index fa392a4c3e45..abfd96091d7e 100644 --- a/layout/style/Loader.h +++ b/layout/style/Loader.h @@ -489,6 +489,10 @@ private: void BlockOnload(); void UnblockOnload(bool aFireSync); + // Helper to select the correct dispatch target for asynchronous events for + // this loader. + already_AddRefed DispatchTarget(); + nsresult CheckContentPolicy(nsIPrincipal* aLoadingPrincipal, nsIPrincipal* aTriggeringPrincipal, nsIURI* aTargetURI,