Bug 1532261 - merge nsICMSMessage2 and nsICMSMessage into nsICMSMessage. r=kaie,jorgk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 04 Mar 2019 22:59:57 +0100
changeset 33852 664daac5ba9ca4c87aee5d735f4451b90f94d66b
parent 33851 444150fd57c91e11932890b0936acebabdba0dc3
child 33853 01272729816f6b1f514c257f44e3ec66611ad6ce
push id2390
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:12:16 +0000
treeherdercomm-beta@29b1f2c027d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaie, jorgk
bugs1532261
Bug 1532261 - merge nsICMSMessage2 and nsICMSMessage into nsICMSMessage. r=kaie,jorgk
mailnews/mime/public/moz.build
mailnews/mime/public/nsICMSMessage.idl
mailnews/mime/public/nsICMSMessage2.idl
mailnews/mime/src/mimecms.cpp
mailnews/mime/src/nsCMS.cpp
mailnews/mime/src/nsCMS.h
--- a/mailnews/mime/public/moz.build
+++ b/mailnews/mime/public/moz.build
@@ -3,17 +3,16 @@
 # 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/.
 
 XPIDL_SOURCES += [
     'msgIStructuredHeaders.idl',
     'nsICMSDecoder.idl',
     'nsICMSEncoder.idl',
     'nsICMSMessage.idl',
-    'nsICMSMessage2.idl',
     'nsICMSMessageErrors.idl',
     'nsICMSSecureMessage.idl',
     'nsIMimeConverter.idl',
     'nsIMimeEmitter.idl',
     'nsIMimeHeaders.idl',
     'nsIMimeMiscStatus.idl',
     'nsIMimeStreamConverter.idl',
     'nsIMsgHeaderParser.idl',
--- a/mailnews/mime/public/nsICMSMessage.idl
+++ b/mailnews/mime/public/nsICMSMessage.idl
@@ -1,19 +1,25 @@
 /* -*- 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 "nsISupports.idl"
 
+interface nsISMimeVerificationListener;
+
 %{ C++
 #define NS_CMSMESSAGE_CONTRACTID "@mozilla.org/nsCMSMessage;1"
 %}
 
+/*
+ * At the time the ptr type is eliminated in both interfaces, both should be
+ * made scriptable.
+ */
 [ptr] native UnsignedCharPtr(unsigned char);
 
 interface nsIX509Cert;
 interface nsIArray;
 
 /**
  * nsICMSMessage
  *  Interface to a CMS Message
@@ -32,10 +38,55 @@ interface nsICMSMessage : nsISupports
                                in unsigned long aDigestDataLen,
                                in int16_t aDigestType);
   void CreateEncrypted(in nsIArray aRecipientCerts);
 
   /* The parameter aDigestType must be one of the values in nsICryptoHash */
   void CreateSigned(in nsIX509Cert scert, in nsIX509Cert ecert,
                     in UnsignedCharPtr aDigestData,
                     in unsigned long aDigestDataLen, in int16_t aDigestType);
+
+  /**
+    * Async version of nsICMSMessage::VerifySignature.
+    * Code will be executed on a background thread and
+    * availability of results will be notified using a
+    * call to nsISMimeVerificationListener.
+   */
+  void asyncVerifySignature(in nsISMimeVerificationListener listener);
+
+  /**
+    * Async version of nsICMSMessage::VerifyDetachedSignature.
+    * Code will be executed on a background thread and
+    * availability of results will be notified using a
+    * call to nsISMimeVerificationListener.
+    *
+    * We are using "native unsigned char" ptr, because the function
+    * signatures of this one and nsICMSMessage::verifyDetachedSignature
+    * should be the identical.
+    *
+    * Once both interfaces get cleaned up (bug 330503), the function signature
+    * should look like:
+    *     [array, length_is(aDigestDataLen)] or [const, array, length_is(aDigestDataLen])
+    *     in octet aDigestData,
+    *     in unsigned long aDigestDataLen);
+    *
+    * Set aDigestType to one of the values from nsICryptoHash.
+   */
+  void asyncVerifyDetachedSignature(in nsISMimeVerificationListener listener,
+                                    in UnsignedCharPtr aDigestData,
+                                    in unsigned long aDigestDataLen,
+                                    in int16_t aDigestType);
 };
 
+[uuid(5226d698-0773-4f25-b94c-7944b3fc01d3)]
+interface nsISMimeVerificationListener : nsISupports {
+
+  /**
+   * Notify that results are ready, that have been requested
+   * using nsICMSMessage::asyncVerify[Detached]Signature()
+   *
+   * verificationResultCode matches synchronous result code from
+   * nsICMSMessage::verify[Detached]Signature
+   */
+  void notify(in nsICMSMessage verifiedMessage,
+              in nsresult verificationResultCode);
+};
+
deleted file mode 100644
--- a/mailnews/mime/public/nsICMSMessage2.idl
+++ /dev/null
@@ -1,67 +0,0 @@
-/* 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 "nsISupports.idl"
-
-interface nsISMimeVerificationListener;
-
-[ptr] native UnsignedCharPtr(unsigned char);
-
-/*
- * This interface is currently not marked scriptable,
- * because its verification functions are meant to look like those
- * in nsICMSMessage. At the time the ptr type is eliminated in both
- * interfaces, both should be made scriptable.
- */
-
-[uuid(b21a3636-2287-4b9f-9a22-25f245981ef0)]
-interface nsICMSMessage2 : nsISupports
-{
-  /**
-    * Async version of nsICMSMessage::VerifySignature.
-    * Code will be executed on a background thread and
-    * availability of results will be notified using a
-    * call to nsISMimeVerificationListener.
-   */
-  void asyncVerifySignature(in nsISMimeVerificationListener listener);
-
-  /**
-    * Async version of nsICMSMessage::VerifyDetachedSignature.
-    * Code will be executed on a background thread and
-    * availability of results will be notified using a
-    * call to nsISMimeVerificationListener.
-    *
-    * We are using "native unsigned char" ptr, because the function
-    * signatures of this one and nsICMSMessage::verifyDetachedSignature
-    * should be the identical. Cleaning up nsICMSMessages needs to be
-    * postponed, because this async version is needed on MOZILLA_1_8_BRANCH.
-    *
-    * Once both interfaces get cleaned up, the function signature should
-    * look like:
-    *     [array, length_is(aDigestDataLen)]
-    *     in octet aDigestData,
-    *     in unsigned long aDigestDataLen);
-    *
-    * Set aDigestType to one of the values from nsICryptoHash.
-   */
-  void asyncVerifyDetachedSignature(in nsISMimeVerificationListener listener,
-                                    in UnsignedCharPtr aDigestData,
-                                    in unsigned long aDigestDataLen,
-                                    in int16_t aDigestType);
-};
-
-[uuid(5226d698-0773-4f25-b94c-7944b3fc01d3)]
-interface nsISMimeVerificationListener : nsISupports {
-
-  /**
-   *  Notify that results are ready, that have been requested
-   *  using nsICMSMessage2::asyncVerify[Detached]Signature()
-   *
-   *  verificationResultCode matches synchronous result code from
-   *  nsICMSMessage::verify[Detached]Signature
-   */
-  void notify(in nsICMSMessage2 verifiedMessage,
-              in nsresult verificationResultCode);
-};
-
--- a/mailnews/mime/src/mimecms.cpp
+++ b/mailnews/mime/src/mimecms.cpp
@@ -1,15 +1,14 @@
 /* -*- 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 "nsICMSMessage.h"
-#include "nsICMSMessage2.h"
 #include "nsICMSMessageErrors.h"
 #include "nsICMSDecoder.h"
 #include "mimecms.h"
 #include "mimemsig.h"
 #include "nspr.h"
 #include "mimemsg.h"
 #include "mimemoz2.h"
 #include "nsIURI.h"
@@ -296,47 +295,44 @@ nsSMimeVerificationListener::nsSMimeVeri
   mMimeNestingLevel = aMimeNestingLevel;
 
   mFromAddr = aFromAddr;
   mFromName = aFromName;
   mSenderAddr = aSenderAddr;
   mSenderName = aSenderName;
 }
 
-NS_IMETHODIMP nsSMimeVerificationListener::Notify(nsICMSMessage2 *aVerifiedMessage,
+NS_IMETHODIMP nsSMimeVerificationListener::Notify(nsICMSMessage *aVerifiedMessage,
                                                   nsresult aVerificationResultCode)
 {
   // Only continue if we have a valid pointer to the UI
   NS_ENSURE_FALSE(mSinkIsNull, NS_OK);
 
   NS_ENSURE_TRUE(aVerifiedMessage, NS_ERROR_FAILURE);
 
-  nsCOMPtr<nsICMSMessage> msg = do_QueryInterface(aVerifiedMessage);
-  NS_ENSURE_TRUE(msg, NS_ERROR_FAILURE);
-
   nsCOMPtr<nsIX509Cert> signerCert;
-  msg->GetSignerCert(getter_AddRefs(signerCert));
+  aVerifiedMessage->GetSignerCert(getter_AddRefs(signerCert));
 
   int32_t signature_status = nsICMSMessageErrors::GENERAL_ERROR;
 
   if (NS_FAILED(aVerificationResultCode))
   {
     if (NS_ERROR_MODULE_SECURITY == NS_ERROR_GET_MODULE(aVerificationResultCode))
       signature_status = NS_ERROR_GET_CODE(aVerificationResultCode);
     else if (NS_ERROR_NOT_IMPLEMENTED == aVerificationResultCode)
       signature_status = nsICMSMessageErrors::VERIFY_ERROR_PROCESSING;
   }
   else
   {
     bool signing_cert_without_email_address;
 
-    bool good_p = MimeCMSHeadersAndCertsMatch(msg, signerCert,
-                                                mFromAddr.get(), mFromName.get(),
-                                                mSenderAddr.get(), mSenderName.get(),
-                                                &signing_cert_without_email_address);
+    bool good_p = MimeCMSHeadersAndCertsMatch(aVerifiedMessage, signerCert,
+                                              mFromAddr.get(), mFromName.get(),
+                                              mSenderAddr.get(), mSenderName.get(),
+                                              &signing_cert_without_email_address);
     if (!good_p)
     {
       if (signing_cert_without_email_address)
         signature_status = nsICMSMessageErrors::VERIFY_CERT_WITHOUT_ADDRESS;
       else
         signature_status = nsICMSMessageErrors::VERIFY_HEADER_MISMATCH;
     }
     else
@@ -571,30 +567,23 @@ void MimeCMSGetFromSender(MimeObject *ob
 
 void MimeCMSRequestAsyncSignatureVerification(nsICMSMessage *aCMSMsg,
                                               const char *aFromAddr, const char *aFromName,
                                               const char *aSenderAddr, const char *aSenderName,
                                               nsIMsgSMIMEHeaderSink *aHeaderSink, int32_t aMimeNestingLevel,
                                               unsigned char* item_data, uint32_t item_len,
                                               int16_t digest_type)
 {
-  nsCOMPtr<nsICMSMessage2> msg2 = do_QueryInterface(aCMSMsg);
-  if (!msg2)
-    return;
-
   RefPtr<nsSMimeVerificationListener> listener =
     new nsSMimeVerificationListener(aFromAddr, aFromName, aSenderAddr, aSenderName,
                                     aHeaderSink, aMimeNestingLevel);
-  if (!listener)
-    return;
-
   if (item_data)
-    msg2->AsyncVerifyDetachedSignature(listener, item_data, item_len, digest_type);
+    aCMSMsg->AsyncVerifyDetachedSignature(listener, item_data, item_len, digest_type);
   else
-    msg2->AsyncVerifySignature(listener);
+    aCMSMsg->AsyncVerifySignature(listener);
 }
 
 static int
 MimeCMS_eof (void *crypto_closure, bool abort_p)
 {
   MimeCMSdata *data = (MimeCMSdata *) crypto_closure;
   nsresult rv;
   int32_t status = nsICMSMessageErrors::SUCCESS;
--- a/mailnews/mime/src/nsCMS.cpp
+++ b/mailnews/mime/src/nsCMS.cpp
@@ -28,17 +28,17 @@
 #include "mozilla/StaticMutex.h"
 
 using namespace mozilla;
 using namespace mozilla::psm;
 using namespace mozilla::pkix;
 
 extern mozilla::LazyLogModule gPIPNSSLog;
 
-NS_IMPL_ISUPPORTS(nsCMSMessage, nsICMSMessage, nsICMSMessage2)
+NS_IMPL_ISUPPORTS(nsCMSMessage, nsICMSMessage)
 
 nsCMSMessage::nsCMSMessage()
 {
   m_cmsMsg = nullptr;
 }
 nsCMSMessage::nsCMSMessage(NSSCMSMessage *aCMSMsg)
 {
   m_cmsMsg = aCMSMsg;
@@ -402,19 +402,17 @@ private:
       rv = mMessage->VerifySignature();
     }
 
     return rv;
   }
   virtual void CallCallback(nsresult rv) override
   {
     MOZ_ASSERT(NS_IsMainThread());
-
-    nsCOMPtr<nsICMSMessage2> m2 = do_QueryInterface(mMessage);
-    mListener->Notify(m2, rv);
+    mListener->Notify(mMessage, rv);
   }
 
   nsCOMPtr<nsICMSMessage> mMessage;
   nsCOMPtr<nsISMimeVerificationListener> mListener;
   nsCString mDigestData;
   int16_t mDigestType;
 
   static mozilla::StaticMutex sMutex;
--- a/mailnews/mime/src/nsCMS.h
+++ b/mailnews/mime/src/nsCMS.h
@@ -5,32 +5,29 @@
 
 #ifndef __NS_CMS_H__
 #define __NS_CMS_H__
 
 #include "nsISupports.h"
 #include "nsCOMPtr.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsICMSMessage.h"
-#include "nsICMSMessage2.h"
 #include "nsICMSEncoder.h"
 #include "nsICMSDecoder.h"
 #include "sechash.h"
 #include "cms.h"
 
 #define NS_CMSMESSAGE_CID \
   { 0xa4557478, 0xae16, 0x11d5, { 0xba,0x4b,0x00,0x10,0x83,0x03,0xb1,0x17 } }
 
-class nsCMSMessage : public nsICMSMessage,
-                     public nsICMSMessage2
+class nsCMSMessage : public nsICMSMessage
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSICMSMESSAGE
-  NS_DECL_NSICMSMESSAGE2
 
   nsCMSMessage();
   explicit nsCMSMessage(NSSCMSMessage* aCMSMsg);
   nsresult Init();
 
   void referenceContext(nsIInterfaceRequestor* aContext) {m_ctx = aContext;}
   NSSCMSMessage* getCMS() {return m_cmsMsg;}
 private: