From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- netwerk/base/nsStreamListenerWrapper.h | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 netwerk/base/nsStreamListenerWrapper.h (limited to 'netwerk/base/nsStreamListenerWrapper.h') diff --git a/netwerk/base/nsStreamListenerWrapper.h b/netwerk/base/nsStreamListenerWrapper.h new file mode 100644 index 0000000000..a950837297 --- /dev/null +++ b/netwerk/base/nsStreamListenerWrapper.h @@ -0,0 +1,65 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef nsStreamListenerWrapper_h__ +#define nsStreamListenerWrapper_h__ + +#include "nsCOMPtr.h" +#include "nsIRequest.h" +#include "nsIStreamListener.h" +#include "nsIThreadRetargetableStreamListener.h" +#include "nsIMultiPartChannel.h" +#include "mozilla/Attributes.h" + +namespace mozilla { +namespace net { + +// Wrapper class to make replacement of nsHttpChannel's listener +// from JavaScript possible. It is workaround for bug 433711 and 682305. +class nsStreamListenerWrapper final + : public nsIMultiPartChannelListener, + public nsIThreadRetargetableStreamListener { + public: + explicit nsStreamListenerWrapper(nsIStreamListener* listener) + : mListener(listener) { + MOZ_ASSERT(mListener, "no stream listener specified"); + } + + NS_DECL_THREADSAFE_ISUPPORTS + NS_FORWARD_SAFE_NSISTREAMLISTENER(mListener) + NS_DECL_NSIMULTIPARTCHANNELLISTENER + NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER + + // Don't use NS_FORWARD_NSIREQUESTOBSERVER(mListener->) here, because we need + // to release mListener in OnStopRequest, and IDL-generated function doesn't. + NS_IMETHOD OnStartRequest(nsIRequest* aRequest) override { + // OnStartRequest can come after OnStopRequest in certain cases (multipart + // listeners) + nsCOMPtr multiPartChannel = + do_QueryInterface(aRequest); + if (multiPartChannel) { + mIsMulti = true; + } + return mListener->OnStartRequest(aRequest); + } + NS_IMETHOD OnStopRequest(nsIRequest* aRequest, + nsresult aStatusCode) override { + nsresult rv = mListener->OnStopRequest(aRequest, aStatusCode); + if (!mIsMulti) { + // Multipart channels can call OnStartRequest again + mListener = nullptr; + } + return rv; + } + + private: + bool mIsMulti{false}; + ~nsStreamListenerWrapper() = default; + nsCOMPtr mListener; +}; + +} // namespace net +} // namespace mozilla + +#endif // nsStreamListenerWrapper_h__ -- cgit v1.2.3