Bug 1490626 - Add new notifications we need for WebExt address book API; r=mkmelin a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 27 Sep 2018 12:01:04 +1200
changeset 31988 7afc65db094f2c60dda0e65753d3ddf8b87717a4
parent 31987 707388b59cb577cad0242f36bfa15d902ff65408
child 31989 a85161ecb5ead8f46cd51a37494a9501c5ae8aaa
push id125
push usermozilla@jorgk.com
push dateSat, 15 Dec 2018 22:50:19 +0000
treeherdercomm-esr60@a85161ecb5ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, jorgk
bugs1490626
Bug 1490626 - Add new notifications we need for WebExt address book API; r=mkmelin a=jorgk
mailnews/addrbook/src/nsAbMDBDirectory.cpp
mailnews/addrbook/src/nsAddrDatabase.cpp
--- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp
@@ -22,16 +22,18 @@
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsIFile.h"
 #include "nsComponentManagerUtils.h"
 #include "nsMemory.h"
 #include "nsArrayUtils.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/DebugOnly.h"
+#include "nsIObserverService.h"
+#include "mozilla/Services.h"
 
 nsAbMDBDirectory::nsAbMDBDirectory(void):
      nsAbMDBDirProperty(),
      mPerformingQuery(false)
 {
 }
 
 nsAbMDBDirectory::~nsAbMDBDirectory(void)
@@ -656,20 +658,27 @@ NS_IMETHODIMP nsAbMDBDirectory::AddCard(
 
   nsresult rv = NS_OK;
   if (!mDatabase)
     rv = GetAbDatabase();
 
   if (NS_FAILED(rv) || !mDatabase)
     return NS_ERROR_FAILURE;
 
-  if (m_IsMailList)
+  if (m_IsMailList) {
     rv = mDatabase->CreateNewListCardAndAddToDB(this, m_dbRowID, card, true /* notify */);
-  else
+  } else {
     rv = mDatabase->CreateNewCardAndAddToDB(card, true, this);
+    nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
+    if (observerService) {
+      nsAutoCString thisUID;
+      this->GetUID(thisUID);
+      observerService->NotifyObservers(card, "addrbook-contact-created", NS_ConvertUTF8toUTF16(thisUID).get());
+    }
+  }
   NS_ENSURE_SUCCESS(rv, rv);
 
   mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
 
   NS_IF_ADDREF(*addedCard = card);
   return NS_OK;
 }
 
@@ -681,16 +690,24 @@ NS_IMETHODIMP nsAbMDBDirectory::ModifyCa
   if (!mDatabase)
   {
     rv = GetAbDatabase();
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   rv = mDatabase->EditCard(aModifiedCard, true, this);
   NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
+  if (observerService) {
+    nsAutoCString thisUID;
+    this->GetUID(thisUID);
+    observerService->NotifyObservers(aModifiedCard, "addrbook-contact-updated", NS_ConvertUTF8toUTF16(thisUID).get());
+  }
+
   return mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
 }
 
 NS_IMETHODIMP nsAbMDBDirectory::DropCard(nsIAbCard* aCard, bool needToCopyCard)
 {
   NS_ENSURE_ARG_POINTER(aCard);
 
   if (mIsQueryURI)
@@ -725,16 +742,22 @@ NS_IMETHODIMP nsAbMDBDirectory::DropCard
       mDatabase->FindRowByCard(newCard, getter_AddRefs(cardRow));
       if (!cardRow)
         mDatabase->CreateNewCardAndAddToDB(newCard, true /* notify */, this);
       else
         mDatabase->InitCardFromRow(newCard, cardRow);
     }
     // since we didn't copy the card, we don't have to notify that it was inserted
     mDatabase->CreateNewListCardAndAddToDB(this, m_dbRowID, newCard, false /* notify */);
+    nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
+    if (observerService) {
+      nsAutoCString thisUID;
+      this->GetUID(thisUID);
+      observerService->NotifyObservers(newCard, "addrbook-list-member-added", NS_ConvertUTF8toUTF16(thisUID).get());
+    }
   }
   else {
     mDatabase->CreateNewCardAndAddToDB(newCard, true /* notify */, this);
   }
   mDatabase->Commit(nsAddrDBCommitType::kLargeCommit);
   return NS_OK;
 }
 
--- a/mailnews/addrbook/src/nsAddrDatabase.cpp
+++ b/mailnews/addrbook/src/nsAddrDatabase.cpp
@@ -26,16 +26,17 @@
 #include "nsIProperty.h"
 #include "nsIVariant.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIAbManager.h"
 #include "mozilla/Services.h"
+#include "nsIObserverService.h"
 
 #define ID_PAB_TABLE            1
 #define ID_DELETEDCARDS_TABLE           2
 
 // There's two books by default, although Mac may have one more, so set this
 // to three. Its not going to affect much, but will save us a few reallocations
 // when the cache is allocated.
 const uint32_t kInitialAddrDBCacheSize = 3;
@@ -1843,16 +1844,21 @@ NS_IMETHODIMP nsAddrDatabase::EditMailLi
   if (notify)
   {
     NotifyListEntryChange(AB_NotifyPropertyChanged, mailList);
 
     if (listCard)
     {
       NotifyCardEntryChange(AB_NotifyPropertyChanged, listCard, mailList);
     }
+
+    nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
+    if (observerService) {
+      observerService->NotifyObservers(mailList, "addrbook-list-updated", nullptr);
+    }
   }
 
   NS_RELEASE(pListRow);
   return NS_OK;
 }
 
 NS_IMETHODIMP nsAddrDatabase::ContainsMailList(nsIAbDirectory *mailList, bool *hasList)
 {