Bug 1371893 - Stop relying on nsIStringInputStream inheriting from nsIInputStream in comm-central code. r=jorgk,rkent
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 09 Jun 2017 23:45:41 -0400
changeset 29209 8cd587465eab8d99bbd718431f37dd1acd1f44a1
parent 29208 ef6dca7cc6cd3ee6c718489be624c606597b34df
child 29210 32a18ec6f4de61ece6d3103ce735b4917cbeaa2d
push id2068
push userclokep@gmail.com
push dateMon, 13 Nov 2017 19:02:14 +0000
treeherdercomm-beta@9c7e7ce8672b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk, rkent
bugs1371893
Bug 1371893 - Stop relying on nsIStringInputStream inheriting from nsIInputStream in comm-central code. r=jorgk,rkent
calendar/base/backend/libical/calICSService.cpp
mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
mailnews/base/util/nsMsgUtils.cpp
mailnews/imap/src/nsImapMailFolder.cpp
--- a/calendar/base/backend/libical/calICSService.cpp
+++ b/calendar/base/backend/libical/calICSService.cpp
@@ -996,26 +996,25 @@ NS_IMETHODIMP
 calIcalComponent::SerializeToICSStream(nsIInputStream **aStreamResult)
 {
     NS_ENSURE_ARG_POINTER(aStreamResult);
 
     char *icalstr;
     nsresult rv = Serialize(&icalstr);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    nsCOMPtr<nsIStringInputStream> const aStringStream(
+    nsCOMPtr<nsIStringInputStream> aStringStream(
         do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
     // copies the string into the input stream that's handed back.
     // This copy is necessary because we don't really own icalstr;
     // it's one of libical's ring buffers
     rv = aStringStream->SetData(icalstr, -1);
     NS_ENSURE_SUCCESS(rv, rv);
-    NS_ADDREF(*aStreamResult = aStringStream);
-    return rv;
+    return CallQueryInterface(aStringStream, aStreamResult);
 }
 
 nsresult
 calIcalComponent::Serialize(char **icalstr)
 {
     NS_ENSURE_ARG_POINTER(icalstr);
 
     // add the timezone bits
--- a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
+++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
@@ -22,16 +22,17 @@
 #include "nsITreeView.h"
 #include "nsIStringBundle.h"
 #include "nsIServiceManager.h"
 #include "mozilla/Services.h"
 #include "nsIAsyncInputStream.h"
 #include "nsIAsyncOutputStream.h"
 #include "nsIPipe.h"
 #include "nsIPrincipal.h"
+#include "nsIInputStream.h"
 
 nsAddbookProtocolHandler::nsAddbookProtocolHandler()
 {
   mAddbookOperation = nsIAddbookUrlOperation::InvalidUrl;
 }
 
 nsAddbookProtocolHandler::~nsAddbookProtocolHandler()
 {
@@ -94,34 +95,35 @@ nsAddbookProtocolHandler::GenerateXMLOut
   nsCOMPtr<nsIStringInputStream> inStr(do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_ConvertUTF16toUTF8 utf8String(aOutput.get());
 
   rv = inStr->SetData(utf8String.get(), utf8String.Length());
   NS_ENSURE_SUCCESS(rv, rv);
 
+  nsCOMPtr<nsIInputStream> stream(do_QueryInterface(inStr));
   if (aLoadInfo) {
     return NS_NewInputStreamChannelInternal(_retval,
                                             aURI,
-                                            inStr,
+                                            stream,
                                             NS_LITERAL_CSTRING("text/xml"),
                                             EmptyCString(),
                                             aLoadInfo);
   }
 
   nsCOMPtr<nsIPrincipal> nullPrincipal =
     do_CreateInstance("@mozilla.org/nullprincipal;1", &rv);
   NS_ASSERTION(NS_SUCCEEDED(rv), "CreateInstance of nullprincipalfailed.");
   if (NS_FAILED(rv))
       return rv;
 
   return NS_NewInputStreamChannel(_retval,
                                   aURI,
-                                  inStr,
+                                  stream,
                                   nullPrincipal,
                                   nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
                                   nsIContentPolicy::TYPE_OTHER,
                                   NS_LITERAL_CSTRING("text/xml"));
 }
 
 NS_IMETHODIMP
 nsAddbookProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
--- a/mailnews/base/util/nsMsgUtils.cpp
+++ b/mailnews/base/util/nsMsgUtils.cpp
@@ -72,16 +72,17 @@
 #include "nsIParserUtils.h"
 #include "nsICharsetConverterManager.h"
 #include "nsIDocumentEncoder.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Services.h"
 #include "locale.h"
 #include "nsStringStream.h"
 #include "nsIInputStreamPump.h"
+#include "nsIInputStream.h"
 #include "nsIChannel.h"
 
 /* for logging to Error Console */
 #include "nsIScriptError.h"
 #include "nsIConsoleService.h"
 
 // Log an error string to the error console
 // (adapted from nsContentUtils::LogSimpleConsoleError).
@@ -1918,18 +1919,20 @@ MsgStreamMsgHeaders(nsIInputStream *aInp
     msgHeaders.Append(curLine);
     msgHeaders.AppendLiteral("\r\n");
   }
   lineBuffer = nullptr;
   nsCOMPtr<nsIStringInputStream> hdrsStream =
         do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   hdrsStream->SetData(msgHeaders.get(), msgHeaders.Length());
+  nsCOMPtr<nsIInputStream> stream(do_QueryInterface(hdrsStream));
+
   nsCOMPtr<nsIInputStreamPump> pump;
-  rv = NS_NewInputStreamPump(getter_AddRefs(pump), hdrsStream);
+  rv = NS_NewInputStreamPump(getter_AddRefs(pump), stream);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return pump->AsyncRead(aConsumer, nullptr);
 }
 
 class CharsetDetectionObserver : public nsICharsetDetectionObserver
 {
 public:
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -2938,18 +2938,20 @@ NS_IMETHODIMP nsImapMailFolder::ParseMsg
       nsCOMPtr <nsIMsgDBHdr> msgHdr;
       headerInfo->GetMsgHdrs(&msgHdrs);
       // create an input stream based on the hdr string.
       nsCOMPtr<nsIStringInputStream> inputStream =
             do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
       NS_ENSURE_SUCCESS(rv, rv);
       inputStream->ShareData(msgHdrs, strlen(msgHdrs));
       GetMessageHeader(msgKey, getter_AddRefs(msgHdr));
-      if (msgHdr)
-        GetMsgPreviewTextFromStream(msgHdr, inputStream);
+      if (msgHdr) {
+        nsCOMPtr<nsIInputStream> stream(do_QueryInterface(inputStream));
+        GetMsgPreviewTextFromStream(msgHdr, stream);
+      }
       continue;
     }
     if (mDatabase && NS_SUCCEEDED(mDatabase->ContainsKey(msgKey, &containsKey)) && containsKey)
     {
       NS_ERROR("downloading hdrs for hdr we already have");
       continue;
     }
     nsresult rv = SetupHeaderParseStream(msgSize, EmptyCString(), nullptr);