From 2e16c9a55132e6a7ea909770357b3ef6957fb962 Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Thu, 27 Sep 2018 12:01:04 +1200 Subject: [PATCH] Bug 1490626 - Add new notifications we need for WebExt address book API; r=mkmelin --- mailnews/addrbook/src/nsAbMDBDirectory.cpp | 27 ++++++++++++++++++++-- mailnews/addrbook/src/nsAddrDatabase.cpp | 6 +++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/mailnews/addrbook/src/nsAbMDBDirectory.cpp b/mailnews/addrbook/src/nsAbMDBDirectory.cpp index 8a88443c99..8cbc88a4ff 100644 --- a/mailnews/addrbook/src/nsAbMDBDirectory.cpp +++ b/mailnews/addrbook/src/nsAbMDBDirectory.cpp @@ -27,6 +27,8 @@ #include "nsArrayUtils.h" #include "nsUnicharUtils.h" #include "mozilla/DebugOnly.h" +#include "nsIObserverService.h" +#include "mozilla/Services.h" nsAbMDBDirectory::nsAbMDBDirectory(void): nsAbMDBDirProperty(), @@ -662,10 +664,17 @@ NS_IMETHODIMP nsAbMDBDirectory::AddCard(nsIAbCard* card, nsIAbCard **addedCard) 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 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); @@ -687,6 +696,14 @@ NS_IMETHODIMP nsAbMDBDirectory::ModifyCard(nsIAbCard *aModifiedCard) rv = mDatabase->EditCard(aModifiedCard, true, this); NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr 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); } @@ -731,6 +748,12 @@ NS_IMETHODIMP nsAbMDBDirectory::DropCard(nsIAbCard* aCard, bool needToCopyCard) } // 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 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); diff --git a/mailnews/addrbook/src/nsAddrDatabase.cpp b/mailnews/addrbook/src/nsAddrDatabase.cpp index 87a46d000a..4935f6f3a1 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.cpp +++ b/mailnews/addrbook/src/nsAddrDatabase.cpp @@ -32,6 +32,7 @@ #include "nsIPrefBranch.h" #include "nsIAbManager.h" #include "mozilla/Services.h" +#include "nsIObserverService.h" #define ID_PAB_TABLE 1 #define ID_DELETEDCARDS_TABLE 2 @@ -1848,6 +1849,11 @@ NS_IMETHODIMP nsAddrDatabase::EditMailList(nsIAbDirectory *mailList, nsIAbCard * { NotifyCardEntryChange(AB_NotifyPropertyChanged, listCard, mailList); } + + nsCOMPtr observerService = mozilla::services::GetObserverService(); + if (observerService) { + observerService->NotifyObservers(mailList, "addrbook-list-updated", nullptr); + } } NS_RELEASE(pListRow);