From d2b6e6de8b6d1e29f7defe96381d80914dd482f2 Mon Sep 17 00:00:00 2001 From: sunil mayya Date: Tue, 24 Oct 2023 01:48:10 +0000 Subject: [PATCH] Bug 1851992 - send onDataFinished notifications from nsInputStreamPump. r=necko-reviewers,jesup Differential Revision: https://phabricator.services.mozilla.com/D188757 --- modules/libpref/init/StaticPrefList.yaml | 6 ++++++ netwerk/base/nsInputStreamPump.cpp | 9 +++++++++ parser/html/nsHtml5StreamParser.cpp | 1 - 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 41723fc88657..0525d1a37f47 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -11673,6 +11673,12 @@ value: @IS_NIGHTLY_BUILD@ mirror: always +# Whether we can send OnDataAvailable to content process directly. +- name: network.send_OnDataFinished.nsInputStreamPump + type: RelaxedAtomicBool + value: @IS_NIGHTLY_BUILD@ + mirror: always + # Perform all network access on the socket process. # The pref requires "network.process.enabled" to be true. # Changing these prefs requires a restart. diff --git a/netwerk/base/nsInputStreamPump.cpp b/netwerk/base/nsInputStreamPump.cpp index 11aac4cd9ba6..dd74aed23ae4 100644 --- a/netwerk/base/nsInputStreamPump.cpp +++ b/netwerk/base/nsInputStreamPump.cpp @@ -14,6 +14,7 @@ #include "mozilla/NonBlockingAsyncInputStream.h" #include "mozilla/ProfilerLabels.h" #include "mozilla/SlicedInputStream.h" +#include "mozilla/StaticPrefs_network.h" #include "nsIStreamListener.h" #include "nsILoadGroup.h" #include "nsNetCID.h" @@ -650,6 +651,14 @@ uint32_t nsInputStreamPump::OnStateStop() { if (!NS_IsMainThread() && !mOffMainThread) { // This method can be called on a different thread if nsInputStreamPump // is used off the main-thread. + if (NS_SUCCEEDED(mStatus) && mListener && + mozilla::StaticPrefs::network_send_OnDataFinished_nsInputStreamPump()) { + nsCOMPtr retargetableListener = + do_QueryInterface(mListener); + if (retargetableListener) { + retargetableListener->OnDataFinished(mStatus); + } + } nsresult rv = mLabeledMainThreadTarget->Dispatch( mozilla::NewRunnableMethod("nsInputStreamPump::CallOnStateStop", this, &nsInputStreamPump::CallOnStateStop)); diff --git a/parser/html/nsHtml5StreamParser.cpp b/parser/html/nsHtml5StreamParser.cpp index d678683d3f69..8f1af6e932bb 100644 --- a/parser/html/nsHtml5StreamParser.cpp +++ b/parser/html/nsHtml5StreamParser.cpp @@ -29,7 +29,6 @@ #include "mozilla/StaticPrefs_html5.h" #include "mozilla/StaticPrefs_intl.h" #include "mozilla/StaticPrefs_network.h" -#include "mozilla/TaskCategory.h" #include "mozilla/TextUtils.h" #include "mozilla/UniquePtrExtensions.h"