Bug 1354040 - nsMIMEInputStream should be nsIIPCSerializableInputStream only if the internal stream is serializable, r=qdot
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 07 Apr 2017 09:34:13 +0200
changeset 351791 f39eb27798df3a54a8bbda84727a98cadec7c328
parent 351790 8519c62fa2e17b99706aa5e592d7156c6d1851fb
child 351792 c1cda5e8a20e6b3ac114633b051ca6f1e9da9948
push id31621
push userarchaeopteryx@coole-files.de
push dateFri, 07 Apr 2017 20:14:04 +0000
treeherdermozilla-central@35c7be9c2db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1354040
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1354040 - nsMIMEInputStream should be nsIIPCSerializableInputStream only if the internal stream is serializable, r=qdot
netwerk/base/nsMIMEInputStream.cpp
--- a/netwerk/base/nsMIMEInputStream.cpp
+++ b/netwerk/base/nsMIMEInputStream.cpp
@@ -49,33 +49,40 @@ private:
         nsCOMPtr<nsIInputStream> mThisStream;
         nsWriteSegmentFun mWriter;
         void* mClosure;
     };
     static nsresult ReadSegCb(nsIInputStream* aIn, void* aClosure,
                               const char* aFromRawSegment, uint32_t aToOffset,
                               uint32_t aCount, uint32_t *aWriteCount);
 
+    bool IsIPCSerializable() const;
+
     nsTArray<HeaderEntry> mHeaders;
 
     nsCOMPtr<nsIInputStream> mStream;
     bool mStartedReading;
 };
 
 NS_IMPL_ADDREF(nsMIMEInputStream)
 NS_IMPL_RELEASE(nsMIMEInputStream)
 
 NS_IMPL_CLASSINFO(nsMIMEInputStream, nullptr, nsIClassInfo::THREADSAFE,
                   NS_MIMEINPUTSTREAM_CID)
 
-NS_IMPL_QUERY_INTERFACE_CI(nsMIMEInputStream,
-                           nsIMIMEInputStream,
-                           nsIInputStream,
-                           nsISeekableStream,
-                           nsIIPCSerializableInputStream)
+NS_INTERFACE_MAP_BEGIN(nsMIMEInputStream)
+  NS_INTERFACE_MAP_ENTRY(nsIMIMEInputStream)
+  NS_INTERFACE_MAP_ENTRY(nsIInputStream)
+  NS_INTERFACE_MAP_ENTRY(nsISeekableStream)
+  NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIIPCSerializableInputStream,
+                                     IsIPCSerializable())
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMIMEInputStream)
+  NS_IMPL_QUERY_CLASSINFO(nsMIMEInputStream)
+NS_INTERFACE_MAP_END
+
 NS_IMPL_CI_INTERFACE_GETTER(nsMIMEInputStream,
                             nsIMIMEInputStream,
                             nsIInputStream,
                             nsISeekableStream)
 
 nsMIMEInputStream::nsMIMEInputStream() : mStartedReading(false)
 {
 }
@@ -325,8 +332,19 @@ nsMIMEInputStream::Deserialize(const Inp
 
 Maybe<uint64_t>
 nsMIMEInputStream::ExpectedSerializedLength()
 {
     nsCOMPtr<nsIIPCSerializableInputStream> serializable = do_QueryInterface(mStream);
     return serializable ? serializable->ExpectedSerializedLength() : Nothing();
 }
 
+bool
+nsMIMEInputStream::IsIPCSerializable() const
+{
+    // If SetData() or Deserialize() has not be called yet, mStream is null.
+    if (!mStream) {
+      return true;
+    }
+
+    nsCOMPtr<nsIIPCSerializableInputStream> serializable = do_QueryInterface(mStream);
+    return !!serializable;
+}