Bug 536289 - Part 1: Move IPC::InputStream to a more general location. r=jduell a=blocking-fennec
authorJosh Matthews <josh@joshmatthews.net>
Thu, 14 Oct 2010 14:21:48 -0400
changeset 56141 290d90eb8ee89dda239ae4ca1c9b331d3d5c625b
parent 56140 446efe4e01ed223df6ef146b1285284dda5c6bad
child 56142 b2cb926d1ea145b44a08a4558aa147371334b597
push idunknown
push userunknown
push dateunknown
reviewersjduell, blocking-fennec
bugs536289
milestone2.0b8pre
Bug 536289 - Part 1: Move IPC::InputStream to a more general location. r=jduell a=blocking-fennec
netwerk/base/src/nsBufferedStreams.cpp
netwerk/base/src/nsMIMEInputStream.cpp
netwerk/ipc/NeckoMessageUtils.h
netwerk/protocol/http/PHttpChannelParams.h
xpcom/io/nsMultiplexInputStream.cpp
--- a/netwerk/base/src/nsBufferedStreams.cpp
+++ b/netwerk/base/src/nsBufferedStreams.cpp
@@ -32,17 +32,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifdef MOZ_IPC
 #include "IPC/IPCMessageUtils.h"
-#include "mozilla/net/PHttpChannelParams.h"
+#include "mozilla/net/NeckoMessageUtils.h"
 #endif
 
 #include "nsBufferedStreams.h"
 #include "nsStreamUtils.h"
 #include "nsCRT.h"
 #include "nsNetCID.h"
 #include "nsIClassInfoImpl.h"
 
--- a/netwerk/base/src/nsMIMEInputStream.cpp
+++ b/netwerk/base/src/nsMIMEInputStream.cpp
@@ -38,17 +38,17 @@
 
 /**
  * The MIME stream separates headers and a datastream. It also allows
  * automatic creation of the content-length header.
  */
 
 #ifdef MOZ_IPC
 #include "IPC/IPCMessageUtils.h"
-#include "mozilla/net/PHttpChannelParams.h"
+#include "mozilla/net/NeckoMessageUtils.h"
 #endif
 
 #include "nsCOMPtr.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIMultiplexInputStream.h"
 #include "nsIMIMEInputStream.h"
 #include "nsISeekableStream.h"
 #include "nsIStringStream.h"
--- a/netwerk/ipc/NeckoMessageUtils.h
+++ b/netwerk/ipc/NeckoMessageUtils.h
@@ -41,16 +41,17 @@
 
 #include "IPC/IPCMessageUtils.h"
 #include "nsStringGlue.h"
 #include "nsIURI.h"
 #include "nsIIPCSerializable.h"
 #include "nsIClassInfo.h"
 #include "nsComponentManagerUtils.h"
 #include "nsNetUtil.h"
+#include "nsStringStream.h"
 
 namespace IPC {
 
 // Since IPDL doesn't have any knowledge of pointers, there's no easy way to
 // pass around nsIURI pointers.  This is a very thin wrapper that IPDL can
 // easily work with, allowing for conversion to and from an nsIURI pointer.
 
 class URI {
@@ -169,16 +170,119 @@ struct ParamTraits<URI>
       aLog->append(StringPrintf(L"[%s]", spec.get()));
     }
     else {
       aLog->append(L"[]");
     }
   }
 };
 
+class InputStream {
+ public:
+  InputStream() : mStream(nsnull) {}
+  InputStream(nsIInputStream* aStream) : mStream(aStream) {}
+  operator nsIInputStream*() const { return mStream.get(); }
+
+  friend struct ParamTraits<InputStream>;
+
+ private:
+  // Unimplemented
+  InputStream& operator=(InputStream&);
+
+  nsCOMPtr<nsIInputStream> mStream;
+};
+
+template<>
+struct ParamTraits<InputStream>
+{
+  typedef InputStream paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    bool isNull = !aParam.mStream;
+    aMsg->WriteBool(isNull);
+
+    if (isNull)
+      return;
+
+    nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(aParam.mStream);
+    bool isSerializable = !!serializable;
+    WriteParam(aMsg, isSerializable);
+
+    if (!serializable) {
+      NS_WARNING("nsIInputStream implementation doesn't support nsIIPCSerializable; falling back to copying data");
+
+      nsCString streamString;
+      PRUint32 bytes;
+
+      aParam.mStream->Available(&bytes);
+      if (bytes > 0) {
+        nsresult rv = NS_ReadInputStreamToString(aParam.mStream, streamString, bytes);
+        NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Can't read input stream into a string!");
+      }
+
+      WriteParam(aMsg, streamString);
+      return;
+    }
+
+    nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(aParam.mStream);
+    char cidStr[NSID_LENGTH];
+    nsCID cid;
+    nsresult rv = classInfo->GetClassIDNoAlloc(&cid);
+    NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "All IPDL streams must report a valid class ID");
+
+    cid.ToProvidedString(cidStr);
+    WriteParam(aMsg, nsCAutoString(cidStr));
+    serializable->Write(aMsg);
+  }
+
+  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
+  {
+    bool isNull;
+    if (!ReadParam(aMsg, aIter, &isNull))
+      return false;
+
+    if (isNull) {
+      aResult->mStream = nsnull;
+      return true;
+    }
+
+    bool isSerializable;
+    if (!ReadParam(aMsg, aIter, &isSerializable))
+      return false;
+
+    nsCOMPtr<nsIInputStream> stream;
+    if (!isSerializable) {
+      nsCString streamString;
+      if (!ReadParam(aMsg, aIter, &streamString))
+        return false;
+
+      nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream), streamString);
+      if (NS_FAILED(rv))
+        return false;
+    } else {
+      nsCAutoString cidStr;
+      nsCID cid;
+      if (!ReadParam(aMsg, aIter, &cidStr) ||
+          !cid.Parse(cidStr.get()))
+        return false;
+
+      stream = do_CreateInstance(cid);
+      if (!stream)
+        return false;
+      nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(stream);
+      if (!serializable || !serializable->Read(aMsg, aIter))
+        return false;
+    }
+
+    stream.swap(aResult->mStream);
+    return true;
+  }
+};
+
 // nsIPermissionManager utilities
 
 struct Permission
 {
   nsCString host, type;
   PRUint32 capability, expireType;
   PRInt64 expireTime;
 
--- a/netwerk/protocol/http/PHttpChannelParams.h
+++ b/netwerk/protocol/http/PHttpChannelParams.h
@@ -44,17 +44,16 @@
 #define ALLOW_LATE_NSHTTP_H_INCLUDE 1
 #include "base/basictypes.h"
 
 #include "IPC/IPCMessageUtils.h"
 #include "nsHttp.h"
 #include "nsHttpHeaderArray.h"
 #include "nsHttpResponseHead.h"
 
-#include "nsStringStream.h"
 #include "nsIIPCSerializable.h"
 #include "nsIClassInfo.h"
 #include "nsNetUtil.h"
 
 namespace mozilla {
 namespace net {
 
 struct RequestHeaderTuple {
@@ -192,114 +191,11 @@ struct ParamTraits<nsHttpResponseHead>
         !ReadParam(aMsg, aIter, &(aResult->mCacheControlNoCache)) ||
         !ReadParam(aMsg, aIter, &(aResult->mPragmaNoCache)))
       return false;
 
     return true;
   }
 };
 
-class InputStream {
-public:
-  InputStream() : mStream(nsnull) {}
-  InputStream(nsIInputStream* aStream) : mStream(aStream) {}
-  operator nsIInputStream*() const { return mStream.get(); }
-
-  friend struct ParamTraits<InputStream>;
-
-private:
-  // Unimplemented
-  InputStream& operator=(InputStream&);
-
-  nsCOMPtr<nsIInputStream> mStream;
-};
-
-template<>
-struct ParamTraits<InputStream>
-{
-  typedef InputStream paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam)
-  {
-    bool isNull = !aParam.mStream;
-    aMsg->WriteBool(isNull);
-
-    if (isNull)
-      return;
-
-    nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(aParam.mStream);
-    bool isSerializable = !!serializable;
-    WriteParam(aMsg, isSerializable);
-
-    if (!serializable) {
-      NS_WARNING("nsIInputStream implementation doesn't support nsIIPCSerializable; falling back to copying data");
-
-      nsCString streamString;
-      PRUint32 bytes;
-
-      aParam.mStream->Available(&bytes);
-      if (bytes > 0) {
-        nsresult rv = NS_ReadInputStreamToString(aParam.mStream, streamString, bytes);
-        NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Can't read input stream into a string!");
-      }
-
-      WriteParam(aMsg, streamString);
-      return;
-    }
-
-    nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(aParam.mStream);
-    char cidStr[NSID_LENGTH];
-    nsCID cid;
-    nsresult rv = classInfo->GetClassIDNoAlloc(&cid);
-    NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "All IPDL streams must report a valid class ID");
-
-    cid.ToProvidedString(cidStr);
-    WriteParam(aMsg, nsCAutoString(cidStr));
-    serializable->Write(aMsg);
-  }
-
-  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
-  {
-    bool isNull;
-    if (!ReadParam(aMsg, aIter, &isNull))
-      return false;
-
-    if (isNull) {
-      aResult->mStream = nsnull;
-      return true;
-    }
-
-    bool isSerializable;
-    if (!ReadParam(aMsg, aIter, &isSerializable))
-      return false;
-
-    nsCOMPtr<nsIInputStream> stream;
-    if (!isSerializable) {
-      nsCString streamString;
-      if (!ReadParam(aMsg, aIter, &streamString))
-        return false;
-
-      nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream), streamString);
-      if (NS_FAILED(rv))
-        return false;
-    } else {
-      nsCAutoString cidStr;
-      nsCID cid;
-      if (!ReadParam(aMsg, aIter, &cidStr) ||
-          !cid.Parse(cidStr.get()))
-        return false;
-
-      stream = do_CreateInstance(cid);
-      if (!stream)
-        return false;
-      nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(stream);
-      if (!serializable || !serializable->Read(aMsg, aIter))
-        return false;
-    }
-
-    stream.swap(aResult->mStream);
-    return true;
-  }
-};
-
 } // namespace IPC
 
 #endif // mozilla_net_PHttpChannelParams_h
--- a/xpcom/io/nsMultiplexInputStream.cpp
+++ b/xpcom/io/nsMultiplexInputStream.cpp
@@ -38,17 +38,17 @@
 
 /**
  * The multiplex stream concatenates a list of input streams into a single
  * stream.
  */
 
 #ifdef MOZ_IPC
 #include "IPC/IPCMessageUtils.h"
-#include "mozilla/net/PHttpChannelParams.h"
+#include "mozilla/net/NeckoMessageUtils.h"
 #endif
 
 #include "nsMultiplexInputStream.h"
 #include "nsIMultiplexInputStream.h"
 #include "nsISeekableStream.h"
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsInt64.h"