Bug 1589922 - Change OnItemPropertyChanged/NotifyItemPropertyChanged to use smart strings in nsIAbListener.idl/nsIAbManager.idl. r=aceman,darktrojan
authorJorg K <jorgk@jorgk.com>
Mon, 21 Oct 2019 00:37:13 +0200
changeset 37196 432747ceaabea65489c44cb156e81cb33ac032ef
parent 37195 32e57b35f3f0e1c77f7736851e8f4e7377263a95
child 37197 0618eba9d869570c63b4e9d20f2d0b1911f82051
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersaceman, darktrojan
bugs1589922
Bug 1589922 - Change OnItemPropertyChanged/NotifyItemPropertyChanged to use smart strings in nsIAbListener.idl/nsIAbManager.idl. r=aceman,darktrojan
mailnews/addrbook/public/nsIAbListener.idl
mailnews/addrbook/public/nsIAbManager.idl
mailnews/addrbook/src/nsAbDirProperty.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.cpp
mailnews/addrbook/src/nsAbMDBDirectory.cpp
mailnews/addrbook/src/nsAbMDBDirectory.h
mailnews/addrbook/src/nsAbManager.cpp
mailnews/addrbook/src/nsAbOSXCard.mm
mailnews/addrbook/src/nsAbOSXDirectory.mm
mailnews/addrbook/src/nsAbView.cpp
mailnews/addrbook/test/unit/test_jsaddrbook.js
mailnews/addrbook/test/unit/test_notifications.js
--- a/mailnews/addrbook/public/nsIAbListener.idl
+++ b/mailnews/addrbook/public/nsIAbListener.idl
@@ -67,24 +67,24 @@ interface nsIAbListener : nsISupports {
    *
    */
   void onItemRemoved(in nsISupports parentDir, in nsISupports item);
 
   /**
    * Called when an address book item is changed. Note the current
    * implementation means that property is either the literal string "DirName"
    * or null, with oldValue and newValue being specified if the property is
-   * "DirName" otherwise they are null.
+   * "DirName" otherwise they are empty.
    *
    * @param       item            The item being updated (a directory or a
    *                              card).
    *
    * @param       property        The property of the item being changed.
    *
    * @param       oldValue        The old value of the item property being
-   *                              changed if it is known, null otherwise.
+   *                              changed if it is known, empty otherwise.
    *
    * @param       newValue        The new value of the item property being
    *                              changed.
    *
    */
-  void onItemPropertyChanged(in nsISupports item, in string property, in wstring oldValue, in wstring newValue);
+  void onItemPropertyChanged(in nsISupports item, in string property, in AString oldValue, in AString newValue);
 };
--- a/mailnews/addrbook/public/nsIAbManager.idl
+++ b/mailnews/addrbook/public/nsIAbManager.idl
@@ -102,18 +102,18 @@ interface nsIAbManager : nsISupports
    *
    * @param  aItem         The items that has changed (e.g. an nsIAbDirectory)
    * @param  aProperty     The property that has changed (e.g. DirName)
    * @param  aOldValue     The old value of the property.
    * @param  aNewValue     The new value of the property.
    */
   void notifyItemPropertyChanged(in nsISupports aItem,
                                  in string aProperty,
-                                 in wstring aOldValue,
-                                 in wstring aNewValue);
+                                 in AString aOldValue,
+                                 in AString aNewValue);
 
   /**
    * Call to notify the registered listeners when a directory item is added.
    *
    * @param  aParentDirectory  The parent directory of the item that has been
    *                           added.
    * @param  aItem             The item that has been added.
    */
--- a/mailnews/addrbook/src/nsAbDirProperty.cpp
+++ b/mailnews/addrbook/src/nsAbDirProperty.cpp
@@ -120,18 +120,17 @@ NS_IMETHODIMP nsAbDirProperty::SetDirNam
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIAbManager> abManager =
       do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
 
   if (NS_SUCCEEDED(rv))
     // We inherit from nsIAbDirectory, so this static cast should be safe.
     abManager->NotifyItemPropertyChanged(static_cast<nsIAbDirectory *>(this),
-                                         "DirName", oldDirName.get(),
-                                         nsString(aDirName).get());
+                                         "DirName", oldDirName, aDirName);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbDirProperty::GetDirType(int32_t *aDirType) {
   return GetIntValue("dirType", LDAPDirectory, aDirType);
 }
 
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
@@ -230,20 +230,22 @@ NS_IMETHODIMP nsAbLDAPDirectory::SetLDAP
   if (oldUrl.IsEmpty() ||
       StringBeginsWith(oldUrl, NS_LITERAL_CSTRING("ldap:")) != newIsNotSecure) {
     // They don't so its time to send round an update.
     nsCOMPtr<nsIAbManager> abManager =
         do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     // We inherit from nsIAbDirectory, so this static cast should be safe.
-    abManager->NotifyItemPropertyChanged(static_cast<nsIAbDirectory *>(this),
-                                         "IsSecure",
-                                         (newIsNotSecure ? u"true" : u"false"),
-                                         (newIsNotSecure ? u"false" : u"true"));
+    NS_NAMED_LITERAL_STRING(trueString, "true");
+    NS_NAMED_LITERAL_STRING(falseString, "false");
+    abManager->NotifyItemPropertyChanged(
+        static_cast<nsIAbDirectory *>(this), "IsSecure",
+        (newIsNotSecure ? trueString : falseString),
+        (newIsNotSecure ? falseString : trueString));
   }
 
   return NS_OK;
 }
 
 /*
  *
  * nsIAbDirectorySearch methods
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -183,25 +183,26 @@ NS_IMETHODIMP nsAbMDBDirectory::DeleteDi
 }
 
 nsresult nsAbMDBDirectory::NotifyItemChanged(nsISupports *item) {
   nsresult rv;
   nsCOMPtr<nsIAbManager> abManager =
       do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = abManager->NotifyItemPropertyChanged(item, nullptr, nullptr, nullptr);
+  rv = abManager->NotifyItemPropertyChanged(item, nullptr, EmptyString(),
+                                            EmptyString());
   NS_ENSURE_SUCCESS(rv, rv);
   return rv;
 }
 
 nsresult nsAbMDBDirectory::NotifyPropertyChanged(nsIAbDirectory *list,
                                                  const char *property,
-                                                 const char16_t *oldValue,
-                                                 const char16_t *newValue) {
+                                                 const nsAString &oldValue,
+                                                 const nsAString &newValue) {
   nsresult rv;
   nsCOMPtr<nsISupports> supports = do_QueryInterface(list, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIAbManager> abManager =
       do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -821,17 +822,17 @@ NS_IMETHODIMP nsAbMDBDirectory::OnListEn
     mozilla::Unused << dblist;
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (bIsMailList) {
       nsString listName;
       rv = list->GetDirName(listName);
       NS_ENSURE_SUCCESS(rv, rv);
 
-      rv = NotifyPropertyChanged(list, "DirName", nullptr, listName.get());
+      rv = NotifyPropertyChanged(list, "DirName", EmptyString(), listName);
       NS_ENSURE_SUCCESS(rv, rv);
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP nsAbMDBDirectory::OnAnnouncerGoingAway() {
   if (mDatabase) mDatabase->RemoveListener(this);
--- a/mailnews/addrbook/src/nsAbMDBDirectory.h
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.h
@@ -83,18 +83,18 @@ class nsAbMDBDirectory
   NS_DECL_NSIABDIRECTORYSEARCH
 
   // nsIAbDirSearchListener methods
   NS_DECL_NSIABDIRSEARCHLISTENER
 
  protected:
   virtual ~nsAbMDBDirectory();
   nsresult NotifyPropertyChanged(nsIAbDirectory *list, const char *property,
-                                 const char16_t *oldValue,
-                                 const char16_t *newValue);
+                                 const nsAString &oldValue,
+                                 const nsAString &newValue);
   nsresult NotifyItemAdded(nsISupports *item);
   nsresult NotifyItemDeleted(nsISupports *item);
   nsresult NotifyItemChanged(nsISupports *item);
   nsresult RemoveCardFromAddressList(nsIAbCard *card);
 
   nsresult GetAbDatabase();
   nsCOMPtr<nsIAddrDatabase> mDatabase;
 
--- a/mailnews/addrbook/src/nsAbManager.cpp
+++ b/mailnews/addrbook/src/nsAbManager.cpp
@@ -373,18 +373,18 @@ NS_IMETHODIMP nsAbManager::RemoveAddress
   while (iter.HasMore()) {                                         \
     const abListener &abL = iter.GetNext();                        \
     if (abL.mNotifyFlags & nsIAbListener::propertyflag_)           \
       abL.mListener->propertyfunc_ params_;                        \
   }                                                                \
   PR_END_MACRO
 
 NS_IMETHODIMP nsAbManager::NotifyItemPropertyChanged(
-    nsISupports *aItem, const char *aProperty, const char16_t *aOldValue,
-    const char16_t *aNewValue) {
+    nsISupports *aItem, const char *aProperty, const nsAString &aOldValue,
+    const nsAString &aNewValue) {
   NOTIFY_AB_LISTENERS(itemChanged, OnItemPropertyChanged,
                       (aItem, aProperty, aOldValue, aNewValue));
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbManager::NotifyDirectoryItemAdded(
     nsIAbDirectory *aParentDirectory, nsISupports *aItem) {
   NOTIFY_AB_LISTENERS(itemAdded, OnItemAdded, (aParentDirectory, aItem));
--- a/mailnews/addrbook/src/nsAbOSXCard.mm
+++ b/mailnews/addrbook/src/nsAbOSXCard.mm
@@ -34,17 +34,17 @@ static void SetStringProperty(nsAbOSXCar
 
   if (!aNotify) {
     aCard->SetPropertyAsAString(aMemberName, aValue);
   } else if (!oldValue.Equals(aValue)) {
     aCard->SetPropertyAsAString(aMemberName, aValue);
 
     nsISupports *supports = NS_ISUPPORTS_CAST(nsAbCardProperty *, aCard);
 
-    aAbManager->NotifyItemPropertyChanged(supports, aMemberName, oldValue.get(), aValue.get());
+    aAbManager->NotifyItemPropertyChanged(supports, aMemberName, oldValue, aValue);
   }
 }
 
 static void SetStringProperty(nsAbOSXCard *aCard, NSString *aValue, const char *aMemberName,
                               bool aNotify, nsIAbManager *aAbManager) {
   nsAutoString value;
   if (aValue) AppendToString(aValue, value);
 
--- a/mailnews/addrbook/src/nsAbOSXDirectory.mm
+++ b/mailnews/addrbook/src/nsAbOSXDirectory.mm
@@ -667,17 +667,17 @@ nsresult nsAbOSXDirectory::Update() {
       recordForUniqueId:[NSString
                             stringWithUTF8String:nsAutoCString(Substring(mURINoQuery, 21)).get()]];
   NSString *stringValue = [card valueForProperty:kABGroupNameProperty];
   if (![stringValue isEqualToString:WrapString(m_ListDirName)]) {
     nsAutoString oldValue(m_ListDirName);
     AssignToString(stringValue, m_ListDirName);
     nsCOMPtr<nsISupports> supports = do_QueryInterface(static_cast<nsIAbDirectory *>(this), &rv);
     NS_ENSURE_SUCCESS(rv, rv);
-    abManager->NotifyItemPropertyChanged(supports, "DirName", oldValue.get(), m_ListDirName.get());
+    abManager->NotifyItemPropertyChanged(supports, "DirName", oldValue, m_ListDirName);
   }
 
   if (groups) {
     mutableArray = [NSMutableArray arrayWithArray:groups];
     nsCOMPtr<nsIAbDirectory> directory;
     // It is ok to use m_AddressList here as only top-level directories have
     // groups, and they will be in m_AddressList
     if (m_AddressList) {
--- a/mailnews/addrbook/src/nsAbView.cpp
+++ b/mailnews/addrbook/src/nsAbView.cpp
@@ -971,18 +971,18 @@ int32_t nsAbView::FindIndexForCard(nsIAb
       return i;
     }
   }
   return CARD_NOT_FOUND;
 }
 
 NS_IMETHODIMP nsAbView::OnItemPropertyChanged(nsISupports *item,
                                               const char *property,
-                                              const char16_t *oldValue,
-                                              const char16_t *newValue) {
+                                              const nsAString &oldValue,
+                                              const nsAString &newValue) {
   nsresult rv;
 
   nsCOMPtr<nsIAbCard> card = do_QueryInterface(item);
   if (!card) return NS_OK;
 
   int32_t index = FindIndexForCard(card);
   if (index == -1) return NS_OK;
 
--- a/mailnews/addrbook/test/unit/test_jsaddrbook.js
+++ b/mailnews/addrbook/test/unit/test_jsaddrbook.js
@@ -74,16 +74,18 @@ var observer = {
 
       for (let i = 0; i < expectedEvent.length; i++) {
         try {
           expectedEvent[i].QueryInterface(Ci.nsIAbCard);
           ok(actualEvent[i].equals(expectedEvent[i]));
         } catch (ex) {
           if (expectedEvent[i] instanceof Ci.nsIAbDirectory) {
             equal(actualEvent[i].UID, expectedEvent[i].UID);
+          } else if (expectedEvent[i] === null) {
+            ok(!actualEvent[i]);
           } else if (expectedEvent[i] !== undefined) {
             equal(actualEvent[i], expectedEvent[i]);
           }
         }
       }
     }
   },
 };
--- a/mailnews/addrbook/test/unit/test_notifications.js
+++ b/mailnews/addrbook/test/unit/test_notifications.js
@@ -79,18 +79,18 @@ add_test(function() {
 
   newCard.lastName = "invalid";
 
   AB.modifyCard(newCard);
 
   Assert.equal(abListener.result[0][0], "onItemPropertyChanged");
   Assert.equal(abListener.result[0][1], newCard);
   Assert.equal(abListener.result[0][2], null);
-  Assert.equal(abListener.result[0][3], null);
-  Assert.equal(abListener.result[0][4], null);
+  Assert.ok(!abListener.result[0][3]);
+  Assert.ok(!abListener.result[0][4]);
   abListener.result = [];
 
   // Test - delete a card
 
   var cardsToDelete = Cc["@mozilla.org/array;1"].createInstance(
     Ci.nsIMutableArray
   );