Bug 1206199 - Extend channelwrapper to mediate OnStartRequest, OnStopRequest, OnDataAvailable. r=sicking, a=sylvestre
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Mon, 05 Oct 2015 19:01:35 -0700
changeset 289554 331b9e49f805
parent 289553 124a1bf2bdfb
child 289555 66c365b5fff5
push id5185
push usercbook@mozilla.com
push date2015-10-15 14:12 +0000
treeherdermozilla-beta@d162e49132eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, sylvestre
bugs1206199
milestone42.0
Bug 1206199 - Extend channelwrapper to mediate OnStartRequest, OnStopRequest, OnDataAvailable. r=sicking, a=sylvestre
netwerk/base/nsSecCheckWrapChannel.cpp
--- a/netwerk/base/nsSecCheckWrapChannel.cpp
+++ b/netwerk/base/nsSecCheckWrapChannel.cpp
@@ -84,16 +84,68 @@ nsSecCheckWrapChannel::nsSecCheckWrapCha
   }
 }
 
 nsSecCheckWrapChannel::~nsSecCheckWrapChannel()
 {
 }
 
 //---------------------------------------------------------
+// SecWrapChannelStreamListener helper
+//---------------------------------------------------------
+
+class SecWrapChannelStreamListener final : public nsIStreamListener
+{
+  public:
+    SecWrapChannelStreamListener(nsIRequest *aRequest,
+                                 nsIStreamListener *aStreamListener)
+    : mRequest(aRequest)
+    , mListener(aStreamListener) {}
+
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSISTREAMLISTENER
+    NS_DECL_NSIREQUESTOBSERVER
+
+  private:
+    ~SecWrapChannelStreamListener() {}
+
+    nsCOMPtr<nsIRequest>        mRequest;
+    nsCOMPtr<nsIStreamListener> mListener;
+};
+
+NS_IMPL_ISUPPORTS(SecWrapChannelStreamListener,
+                  nsIStreamListener,
+                  nsIRequestObserver)
+
+NS_IMETHODIMP
+SecWrapChannelStreamListener::OnStartRequest(nsIRequest *aRequest,
+                                             nsISupports *aContext)
+{
+  return mListener->OnStartRequest(mRequest, aContext);
+}
+
+NS_IMETHODIMP
+SecWrapChannelStreamListener::OnStopRequest(nsIRequest *aRequest,
+                                            nsISupports *aContext,
+                                            nsresult aStatus)
+{
+  return mListener->OnStopRequest(mRequest, aContext, aStatus);
+}
+
+NS_IMETHODIMP
+SecWrapChannelStreamListener::OnDataAvailable(nsIRequest *aRequest,
+                                              nsISupports *aContext,
+                                              nsIInputStream *aInStream,
+                                              uint64_t aOffset,
+                                              uint32_t aCount)
+{
+  return mListener->OnDataAvailable(mRequest, aContext, aInStream, aOffset, aCount);
+}
+
+//---------------------------------------------------------
 // nsIChannel implementation
 //---------------------------------------------------------
 
 NS_IMETHODIMP
 nsSecCheckWrapChannel::GetLoadInfo(nsILoadInfo** aLoadInfo)
 {
   CHANNELWRAPPERLOG(("nsSecCheckWrapChannel::GetLoadInfo() [%p]",this));
   NS_IF_ADDREF(*aLoadInfo = mLoadInfo);
@@ -106,20 +158,21 @@ nsSecCheckWrapChannel::SetLoadInfo(nsILo
   CHANNELWRAPPERLOG(("nsSecCheckWrapChannel::SetLoadInfo() [%p]", this));
   mLoadInfo = aLoadInfo;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSecCheckWrapChannel::AsyncOpen2(nsIStreamListener *aListener)
 {
-  nsCOMPtr<nsIStreamListener> listener = aListener;
-  nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
+  nsCOMPtr<nsIStreamListener> secWrapChannelListener =
+    new SecWrapChannelStreamListener(this, aListener);
+  nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, secWrapChannelListener);
   NS_ENSURE_SUCCESS(rv, rv);
-  return AsyncOpen(listener, nullptr);
+  return AsyncOpen(secWrapChannelListener, nullptr);
 }
 
 NS_IMETHODIMP
 nsSecCheckWrapChannel::Open2(nsIInputStream** aStream)
 {
   nsCOMPtr<nsIStreamListener> listener;
   nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
   NS_ENSURE_SUCCESS(rv, rv);