Bug 1589922 - Change OnItemPropertyChanged/NotifyItemPropertyChanged to use smart strings in nsIAbListener.idl/nsIAbManager.idl. r=aceman draft
authorJorg K <jorgk@jorgk.com>
Sun, 20 Oct 2019 12:03:41 +0200
changeset 80363 b7dca699da3efa9408ca9fd2cab087278f1d90fc
parent 80362 1d552e70103e9740353248e66221e58de6538da1
child 80364 10f3722fce98c43366cc56a114dd0cd5e45d9ff6
push id9577
push usermozilla@jorgk.com
push dateSun, 20 Oct 2019 10:04:58 +0000
treeherdertry-comm-central@10f3722fce98 [default view] [failures only]
reviewersaceman
bugs1589922
Bug 1589922 - Change OnItemPropertyChanged/NotifyItemPropertyChanged to use smart strings in nsIAbListener.idl/nsIAbManager.idl. r=aceman
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
--- a/mailnews/addrbook/public/nsIAbListener.idl
+++ b/mailnews/addrbook/public/nsIAbListener.idl
@@ -81,10 +81,10 @@ interface nsIAbListener : nsISupports {
    *
    * @param       oldValue        The old value of the item property being
    *                              changed if it is known, null 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 ACString 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, VoidString(),
+                                            VoidString());
   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", VoidString(), 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,20 +373,21 @@ 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) {
-  NOTIFY_AB_LISTENERS(itemChanged, OnItemPropertyChanged,
-                      (aItem, aProperty, aOldValue, aNewValue));
+    nsISupports *aItem, const char *aProperty, const nsAString &aOldValue,
+    const nsAString &aNewValue) {
+  NOTIFY_AB_LISTENERS(
+      itemChanged, OnItemPropertyChanged,
+      (aItem, nsDependentCString(aProperty), aOldValue, aNewValue));
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAbManager::NotifyDirectoryItemAdded(
     nsIAbDirectory *aParentDirectory, nsISupports *aItem) {
   NOTIFY_AB_LISTENERS(itemAdded, OnItemAdded, (aParentDirectory, aItem));
   return NS_OK;
 }
--- 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
@@ -970,19 +970,19 @@ int32_t nsAbView::FindIndexForCard(nsIAb
     if (NS_SUCCEEDED(rv) && equals) {
       return i;
     }
   }
   return CARD_NOT_FOUND;
 }
 
 NS_IMETHODIMP nsAbView::OnItemPropertyChanged(nsISupports *item,
-                                              const char *property,
-                                              const char16_t *oldValue,
-                                              const char16_t *newValue) {
+                                              const nsACString &property,
+                                              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;