Bug 1204648 - Support AsyncOpen2,Open2,nsIUploadChannel and nsIUploadChannel2 on nsSecCheckWrapChannelBase. r=sicking, a=sylvestre
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Mon, 14 Sep 2015 14:21:03 -0700
changeset 289281 7677798031de5de7999e0c0e7ffe4999f00620c8
parent 289280 6dce309288326a6b21f6723d47e11edbbcb0d8f2
child 289282 1eba35bfff209358a74bdf5f459de8df2e317054
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking, sylvestre
bugs1204648
milestone42.0a2
Bug 1204648 - Support AsyncOpen2,Open2,nsIUploadChannel and nsIUploadChannel2 on nsSecCheckWrapChannelBase. r=sicking, a=sylvestre
netwerk/base/nsSecCheckWrapChannel.cpp
netwerk/base/nsSecCheckWrapChannel.h
--- a/netwerk/base/nsSecCheckWrapChannel.cpp
+++ b/netwerk/base/nsSecCheckWrapChannel.cpp
@@ -1,13 +1,14 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* 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/. */
 
+#include "nsContentSecurityManager.h"
 #include "nsSecCheckWrapChannel.h"
 #include "nsHttpChannel.h"
 #include "nsCOMPtr.h"
 
 static PRLogModuleInfo*
 GetChannelWrapperLog()
 {
   static PRLogModuleInfo* gChannelWrapperPRLog;
@@ -23,28 +24,32 @@ NS_IMPL_ADDREF(nsSecCheckWrapChannelBase
 NS_IMPL_RELEASE(nsSecCheckWrapChannelBase)
 
 NS_INTERFACE_MAP_BEGIN(nsSecCheckWrapChannelBase)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, mHttpChannelInternal)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIHttpChannel)
   NS_INTERFACE_MAP_ENTRY(nsIRequest)
   NS_INTERFACE_MAP_ENTRY(nsIChannel)
+  NS_INTERFACE_MAP_ENTRY(nsIUploadChannel)
+  NS_INTERFACE_MAP_ENTRY(nsIUploadChannel2)
   NS_INTERFACE_MAP_ENTRY(nsISecCheckWrapChannel)
 NS_INTERFACE_MAP_END
 
 //---------------------------------------------------------
 // nsSecCheckWrapChannelBase implementation
 //---------------------------------------------------------
 
 nsSecCheckWrapChannelBase::nsSecCheckWrapChannelBase(nsIChannel* aChannel)
  : mChannel(aChannel)
  , mHttpChannel(do_QueryInterface(aChannel))
  , mHttpChannelInternal(do_QueryInterface(aChannel))
  , mRequest(do_QueryInterface(aChannel))
+ , mUploadChannel(do_QueryInterface(aChannel))
+ , mUploadChannel2(do_QueryInterface(aChannel))
 {
   MOZ_ASSERT(mChannel, "can not create a channel wrapper without a channel");
 }
 
 nsSecCheckWrapChannelBase::~nsSecCheckWrapChannelBase()
 {
 }
 
@@ -97,8 +102,26 @@ nsSecCheckWrapChannel::GetLoadInfo(nsILo
 
 NS_IMETHODIMP
 nsSecCheckWrapChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
 {
   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);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return AsyncOpen(listener, nullptr);
+}
+
+NS_IMETHODIMP
+nsSecCheckWrapChannel::Open2(nsIInputStream** aStream)
+{
+  nsCOMPtr<nsIStreamListener> listener;
+  nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return Open(aStream);
+}
--- a/netwerk/base/nsSecCheckWrapChannel.h
+++ b/netwerk/base/nsSecCheckWrapChannel.h
@@ -3,16 +3,18 @@
  * 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 nsSecCheckWrapChannel_h__
 #define nsSecCheckWrapChannel_h__
 
 #include "nsIHttpChannel.h"
 #include "nsIHttpChannelInternal.h"
+#include "nsIUploadChannel.h"
+#include "nsIUploadChannel2.h"
 #include "nsISecCheckWrapChannel.h"
 #include "nsIWyciwygChannel.h"
 #include "mozilla/LoadInfo.h"
 
 /*
  * The nsSecCheckWrapChannelBase wraps channels that do *not*
  *  * provide a newChannel2() implementation
  *  * provide get/setLoadInfo functions
@@ -29,56 +31,67 @@
  * We do not want to break those addons hence we wrap such channels
  * using the provided wrapper in this class.
  *
  * Please note that the wrapper only forwards calls for
  *  * nsIRequest
  *  * nsIChannel
  *  * nsIHttpChannel
  *  * nsIHttpChannelInternal
+ *  * nsIUploadChannel
+ *  * nsIUploadChannel2
  *
  * In case any addon needs to query the inner channel this class
  * provides a readonly function to query the wrapped channel.
  *
  */
 
 class nsSecCheckWrapChannelBase : public nsIHttpChannel
                                 , public nsIHttpChannelInternal
                                 , public nsISecCheckWrapChannel
+                                , public nsIUploadChannel
+                                , public nsIUploadChannel2
 {
 public:
   NS_FORWARD_NSIHTTPCHANNEL(mHttpChannel->)
   NS_FORWARD_NSIHTTPCHANNELINTERNAL(mHttpChannelInternal->)
   NS_FORWARD_NSICHANNEL(mChannel->)
   NS_FORWARD_NSIREQUEST(mRequest->)
+  NS_FORWARD_NSIUPLOADCHANNEL(mUploadChannel->)
+  NS_FORWARD_NSIUPLOADCHANNEL2(mUploadChannel2->)
   NS_DECL_NSISECCHECKWRAPCHANNEL
   NS_DECL_ISUPPORTS
 
   explicit nsSecCheckWrapChannelBase(nsIChannel* aChannel);
 
 protected:
   virtual ~nsSecCheckWrapChannelBase();
 
   nsCOMPtr<nsIChannel>             mChannel;
   // We do a QI in the constructor to set the following pointers.
   nsCOMPtr<nsIHttpChannel>         mHttpChannel;
   nsCOMPtr<nsIHttpChannelInternal> mHttpChannelInternal;
   nsCOMPtr<nsIRequest>             mRequest;
+  nsCOMPtr<nsIUploadChannel>       mUploadChannel;
+  nsCOMPtr<nsIUploadChannel2>      mUploadChannel2;
 };
 
-/* We define a separate class here to make it clear that we're
- * overriding Get/SetLoadInfo, rather that using the forwarded
- * implementations provided by NS_FORWARD_NSICHANNEL"
+/* We define a separate class here to make it clear that we're overriding
+ * Get/SetLoadInfo as well as AsyncOpen2() and Open2(), rather that using
+ * the forwarded implementations provided by NS_FORWARD_NSICHANNEL"
  */
 class nsSecCheckWrapChannel : public nsSecCheckWrapChannelBase
 {
 public:
   NS_IMETHOD GetLoadInfo(nsILoadInfo **aLoadInfo);
   NS_IMETHOD SetLoadInfo(nsILoadInfo *aLoadInfo);
 
+  NS_IMETHOD AsyncOpen2(nsIStreamListener *aListener);
+  NS_IMETHOD Open2(nsIInputStream** aStream);
+
   nsSecCheckWrapChannel(nsIChannel* aChannel, nsILoadInfo* aLoadInfo);
 
 protected:
   virtual ~nsSecCheckWrapChannel();
 
   nsCOMPtr<nsILoadInfo> mLoadInfo;
 };