Bug 1512356 - Make nsMsgMailNewsUrl serialisable in a rudimentary way. rs=bustage-fix
authorJorg K <jorgk@jorgk.com>
Fri, 07 Dec 2018 12:10:18 +0100
changeset 33861 e993eb9d7c1b74cf3506fe74be8b44fa5dfac86e
parent 33860 c474610d2c81ffb2986c8f20dff94adb29f8d3e7
child 33862 39222abf711e71a31052733e66bedc3a96ffbb8f
push id388
push userclokep@gmail.com
push dateMon, 28 Jan 2019 20:54:56 +0000
reviewersbustage-fix
bugs1512356
Bug 1512356 - Make nsMsgMailNewsUrl serialisable in a rudimentary way. rs=bustage-fix
mailnews/base/util/nsMsgMailNewsUrl.cpp
mailnews/base/util/nsMsgMailNewsUrl.h
--- a/mailnews/base/util/nsMsgMailNewsUrl.cpp
+++ b/mailnews/base/util/nsMsgMailNewsUrl.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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 "msgCore.h"
 #include "nsMsgMailNewsUrl.h"
 #include "nsMsgBaseCID.h"
+#include "nsMsgLocalCID.h"
 #include "nsIMsgAccountManager.h"
 #include "nsString.h"
 #include "nsILoadGroup.h"
 #include "nsIDocShell.h"
 #include "nsIWebProgress.h"
 #include "nsIWebProgressListener.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
@@ -24,16 +25,18 @@
 #include "prmem.h"
 #include <time.h>
 #include "nsMsgUtils.h"
 #include "mozilla/Services.h"
 #include "nsProxyRelease.h"
 #include "mozilla/Encoding.h"
 #include "nsDocShellLoadState.h"
 #include "nsContentUtils.h"
+#include "nsIObjectInputStream.h"
+#include "nsIObjectOutputStream.h"
 
 nsMsgMailNewsUrl::nsMsgMailNewsUrl()
 {
   // nsIURI specific state
   m_runningUrl = false;
   m_updatingFolder = false;
   m_msgIsInLocalCache = false;
   m_suppressErrorMsgs = false;
@@ -75,19 +78,79 @@ NS_IMPL_RELEASE(nsMsgMailNewsUrl)
 // We want part URLs to QI to nsIURIWithSpecialOrigin so we can give
 // them a "normalized" origin. URLs that already have a "normalized"
 // 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_CONDITIONAL(nsIURIWithSpecialOrigin, m_hasNormalizedOrigin)
 NS_INTERFACE_MAP_END
 
+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;
+  rv = ioService->NewURI(urlstr, nullptr, nullptr, getter_AddRefs(url));
+  NS_ENSURE_SUCCESS(rv, rv);
+  m_baseURL = do_QueryInterface(url);
+  return NS_OK;
+}
+
+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());
+}
+
+NS_IMETHODIMP nsMsgMailNewsUrl::GetInterfaces(uint32_t *count, nsIID ***array) {
+  *count = 0;
+  *array = nullptr;
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgMailNewsUrl::GetScriptableHelper(nsIXPCScriptable **_retval) {
+  *_retval = nullptr;
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgMailNewsUrl::GetContractID(nsACString &aContractID) {
+  aContractID.SetIsVoid(true);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgMailNewsUrl::GetClassDescription(nsACString &aClassDescription) {
+  aClassDescription.SetIsVoid(true);
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsMsgMailNewsUrl::GetClassID(nsCID **aClassID) {
+  *aClassID = (nsCID *)moz_xmalloc(sizeof(nsCID));
+  return GetClassIDNoAlloc(*aClassID);
+}
+
+NS_IMETHODIMP nsMsgMailNewsUrl::GetFlags(uint32_t *aFlags) {
+  *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
+  return NS_OK;
+}
+
+static NS_DEFINE_CID(kNS_MAILBOXURL_CID, NS_MAILBOXURL_CID);
+NS_IMETHODIMP nsMsgMailNewsUrl::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) {
+  *aClassIDNoAlloc = kNS_MAILBOXURL_CID;  // XXX TODO: May need to vary based on type.
+  return NS_OK;
+}
+
 // 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;
--- a/mailnews/base/util/nsMsgMailNewsUrl.h
+++ b/mailnews/base/util/nsMsgMailNewsUrl.h
@@ -21,39 +21,45 @@
 #include "nsILoadGroup.h"
 #include "nsIMsgSearchSession.h"
 #include "nsICacheEntry.h"
 #include "nsICacheSession.h"
 #include "nsIMimeMiscStatus.h"
 #include "nsIWeakReferenceUtils.h"
 #include "nsString.h"
 #include "nsIURIMutator.h"
+#include "nsISerializable.h"
+#include "nsIClassInfo.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 nsIURIWithSpecialOrigin,
+                                     public nsISerializable,
+                                     public nsIClassInfo
 {
 public:
     nsMsgMailNewsUrl();
 
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIMSGMAILNEWSURL
     NS_DECL_NSIURI
     NS_DECL_NSIURL
     NS_DECL_NSIURIWITHSPECIALORIGIN
+    NS_DECL_NSISERIALIZABLE
+    NS_DECL_NSICLASSINFO
 
 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);