Bug 1515337 - Bug 1512356 follow-up: Make nsMsgMailNewsUrl implement nsIIPCSerializableURI. rs=mkmelin DONTBUILD
authorJorg K <jorgk@jorgk.com>
Thu, 20 Dec 2018 10:29:06 +0100
changeset 34035 b382906f387f061ee84197074fd9193420cda84d
parent 34034 04d7082e573a71f892831c1078c8ee03dd0e4207
child 34036 9fe5af480738867284f7c51a6ec1d07f3c08c10b
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersmkmelin
bugs1515337, 1512356
Bug 1515337 - Bug 1512356 follow-up: Make nsMsgMailNewsUrl implement nsIIPCSerializableURI. rs=mkmelin DONTBUILD
mailnews/base/util/nsMsgMailNewsUrl.cpp
mailnews/base/util/nsMsgMailNewsUrl.h
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -80,19 +80,39 @@ NS_IMPL_RELEASE(nsMsgMailNewsUrl)
 // origin should not QI to nsIURIWithSpecialOrigin.
 NS_INTERFACE_MAP_BEGIN(nsMsgMailNewsUrl)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMsgMailNewsUrl)
   NS_INTERFACE_MAP_ENTRY(nsIMsgMailNewsUrl)
   NS_INTERFACE_MAP_ENTRY(nsIURL)
   NS_INTERFACE_MAP_ENTRY(nsIURI)
   NS_INTERFACE_MAP_ENTRY(nsISerializable)
   NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
+  NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableURI)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIURIWithSpecialOrigin, m_hasNormalizedOrigin)
 NS_INTERFACE_MAP_END
 
+//--------------------------
+// Support for serialization
+//--------------------------
+// nsMsgMailNewsUrl is only partly serialized by serializing the "base URL"
+// which is an nsStandardURL, or by only serializing the Spec. This may
+// cause problems in the future. See bug 1512356 and bug 1515337 for details,
+// follow-up in bug 1512698.
+
+//----------------------------------
+// Support for nsIIPCSerializableURI
+//----------------------------------
+void nsMsgMailNewsUrl::Serialize(mozilla::ipc::URIParams &aParams) {
+  nsCOMPtr<nsIIPCSerializableURI> serializable = do_QueryInterface(m_baseURL);
+  return serializable->Serialize(aParams);
+}
+
+//----------------------------
+// Support for nsISerializable
+//----------------------------
 NS_IMETHODIMP nsMsgMailNewsUrl::Read(nsIObjectInputStream *stream) {
   nsAutoCString urlstr;
   nsresult rv = NS_ReadOptionalCString(stream, urlstr);
   NS_ENSURE_SUCCESS(rv, rv);
   nsCOMPtr<nsIIOService> ioService =
     mozilla::services::GetIOService();
   NS_ENSURE_TRUE(ioService, NS_ERROR_UNEXPECTED);
   nsCOMPtr<nsIURI> url;
@@ -104,16 +124,19 @@ NS_IMETHODIMP nsMsgMailNewsUrl::Read(nsI
 
 NS_IMETHODIMP nsMsgMailNewsUrl::Write(nsIObjectOutputStream *stream) {
   nsAutoCString urlstr;
   nsresult rv = m_baseURL->GetSpec(urlstr);
   NS_ENSURE_SUCCESS(rv, rv);
   return NS_WriteOptionalStringZ(stream, urlstr.get());
 }
 
+//-------------------------
+// Support for nsIClassInfo
+//-------------------------
 NS_IMETHODIMP nsMsgMailNewsUrl::GetInterfaces(uint32_t *count, nsIID ***array) {
   *count = 0;
   *array = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgMailNewsUrl::GetScriptableHelper(nsIXPCScriptable **_retval) {
   *_retval = nullptr;
@@ -141,17 +164,19 @@ NS_IMETHODIMP nsMsgMailNewsUrl::GetFlags
 }
 
 static NS_DEFINE_CID(kNS_MSGMAILNEWSURL_CID, NS_MSGMAILNEWSURL_CID);
 NS_IMETHODIMP nsMsgMailNewsUrl::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) {
   *aClassIDNoAlloc = kNS_MSGMAILNEWSURL_CID;
   return NS_OK;
 }
 
-// Support for nsIURIWithSpecialOrigin.
+//------------------------------------
+// Support for nsIURIWithSpecialOrigin
+//------------------------------------
 NS_IMETHODIMP nsMsgMailNewsUrl::GetOrigin(nsIURI **aOrigin)
 {
   MOZ_ASSERT(m_hasNormalizedOrigin,
     "nsMsgMailNewsUrl::GetOrigin() can only be called for URLs with normalized spec");
 
   if (!m_normalizedOrigin) {
     nsCOMPtr <nsIMsgMessageUrl> msgUrl;
     QueryInterface(NS_GET_IID(nsIMsgMessageUrl), getter_AddRefs(msgUrl));
--- a/mailnews/base/util/nsMsgMailNewsUrl.h
+++ b/mailnews/base/util/nsMsgMailNewsUrl.h
@@ -23,43 +23,46 @@
 #include "nsICacheEntry.h"
 #include "nsICacheSession.h"
 #include "nsIMimeMiscStatus.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsString.h"
 #include "nsIURIMutator.h"
 #include "nsISerializable.h"
 #include "nsIClassInfo.h"
+#include "nsIIPCSerializableURI.h"
 
 ///////////////////////////////////////////////////////////////////////////////////
 // Okay, I found that all of the mail and news url interfaces needed to support
 // several common interfaces (in addition to those provided through nsIURI).
 // So I decided to group them all in this implementation so we don't have to
 // duplicate the code.
 //
 //////////////////////////////////////////////////////////////////////////////////
 
 #undef  IMETHOD_VISIBILITY
 #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
 
 class NS_MSG_BASE nsMsgMailNewsUrl : public nsIMsgMailNewsUrl,
                                      public nsIURIWithSpecialOrigin,
                                      public nsISerializable,
-                                     public nsIClassInfo
+                                     public nsIClassInfo,
+                                     public nsIIPCSerializableURI
 {
 public:
     nsMsgMailNewsUrl();
 
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIMSGMAILNEWSURL
     NS_DECL_NSIURI
     NS_DECL_NSIURL
     NS_DECL_NSIURIWITHSPECIALORIGIN
     NS_DECL_NSISERIALIZABLE
     NS_DECL_NSICLASSINFO
+    NS_DECL_NSIIPCSERIALIZABLEURI
 
 protected:
   virtual nsresult Clone(nsIURI **_retval);
   virtual nsresult SetScheme(const nsACString &aScheme);
   virtual nsresult SetUserPass(const nsACString &aUserPass);
   virtual nsresult SetUsername(const nsACString &aUsername);
   virtual nsresult SetPassword(const nsACString &aPassword);
   virtual nsresult SetHostPort(const nsACString &aHostPort);