Bug 1840762 - Don't throttle postMessage for pdf.js. r=smaug

This should be safe to uplift.

Differential Revision: https://phabricator.services.mozilla.com/D198829
This commit is contained in:
Emilio Cobos Álvarez 2024-01-17 21:49:34 +00:00
Родитель 68fc95df81
Коммит 7bf069df3a
3 изменённых файлов: 29 добавлений и 20 удалений

Просмотреть файл

@ -373,11 +373,8 @@ JSObject* BrowsingContextGroup::WrapObject(JSContext* aCx,
return BrowsingContextGroup_Binding::Wrap(aCx, this, aGivenProto);
}
nsresult BrowsingContextGroup::QueuePostMessageEvent(
already_AddRefed<nsIRunnable>&& aRunnable) {
if (!StaticPrefs::dom_separate_event_queue_for_post_message_enabled()) {
return NS_ERROR_FAILURE;
}
nsresult BrowsingContextGroup::QueuePostMessageEvent(nsIRunnable* aRunnable) {
MOZ_ASSERT(StaticPrefs::dom_separate_event_queue_for_post_message_enabled());
if (!mPostMessageEventQueue) {
nsCOMPtr<nsISerialEventTarget> target = GetMainThreadSerialEventTarget();
@ -394,8 +391,7 @@ nsresult BrowsingContextGroup::QueuePostMessageEvent(
MOZ_ALWAYS_SUCCEEDS(rv);
}
mPostMessageEventQueue->Dispatch(std::move(aRunnable), NS_DISPATCH_NORMAL);
return NS_OK;
return mPostMessageEventQueue->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
}
void BrowsingContextGroup::FlushPostMessageEvents() {

Просмотреть файл

@ -145,7 +145,7 @@ class BrowsingContextGroup final : public nsWrapperCache {
}
}
nsresult QueuePostMessageEvent(already_AddRefed<nsIRunnable>&& aRunnable);
nsresult QueuePostMessageEvent(nsIRunnable* aRunnable);
void FlushPostMessageEvents();

Просмотреть файл

@ -257,20 +257,33 @@ void PostMessageEvent::Dispatch(nsGlobalWindowInner* aTargetWindow,
&status);
}
void PostMessageEvent::DispatchToTargetThread(ErrorResult& aError) {
nsCOMPtr<nsIRunnable> event = this;
if (StaticPrefs::dom_separate_event_queue_for_post_message_enabled()) {
BrowsingContext* bc = mTargetWindow->GetBrowsingContext();
bc = bc ? bc->Top() : nullptr;
if (bc && bc->IsLoading()) {
// As long as the top level is loading, we can dispatch events to the
// queue because the queue will be flushed eventually
aError = bc->Group()->QueuePostMessageEvent(event.forget());
return;
}
static nsresult MaybeThrottle(nsGlobalWindowOuter* aTargetWindow,
PostMessageEvent* aEvent) {
BrowsingContext* bc = aTargetWindow->GetBrowsingContext();
if (!bc) {
return NS_ERROR_FAILURE;
}
bc = bc->Top();
if (!bc->IsLoading()) {
return NS_ERROR_FAILURE;
}
if (nsContentUtils::IsPDFJS(aTargetWindow->GetPrincipal())) {
// pdf.js is known to block the load event on a worker's postMessage event.
// Avoid throttling postMessage for pdf.js to avoid pathological wait times,
// see bug 1840762.
return NS_ERROR_FAILURE;
}
if (!StaticPrefs::dom_separate_event_queue_for_post_message_enabled()) {
return NS_ERROR_FAILURE;
}
return bc->Group()->QueuePostMessageEvent(aEvent);
}
aError = mTargetWindow->Dispatch(event.forget());
void PostMessageEvent::DispatchToTargetThread(ErrorResult& aError) {
if (NS_SUCCEEDED(MaybeThrottle(mTargetWindow, this))) {
return;
}
aError = mTargetWindow->Dispatch(do_AddRef(this));
}
} // namespace mozilla::dom