diff --git a/toolkit/components/places/nsINavBookmarksService.idl b/toolkit/components/places/nsINavBookmarksService.idl index 1c54d0231c6e..d1b38b94b205 100644 --- a/toolkit/components/places/nsINavBookmarksService.idl +++ b/toolkit/components/places/nsINavBookmarksService.idl @@ -456,6 +456,5 @@ interface nsINavBookmarksService : nsISupports /** * Gets an array of registered nsINavBookmarkObserver objects. */ - void getObservers([optional] out unsigned long count, - [retval, array, size_is(count)] out nsINavBookmarkObserver observers); + Array getObservers(); }; diff --git a/toolkit/components/places/nsINavHistoryService.idl b/toolkit/components/places/nsINavHistoryService.idl index 2835e40eceec..406f89472479 100644 --- a/toolkit/components/places/nsINavHistoryService.idl +++ b/toolkit/components/places/nsINavHistoryService.idl @@ -1261,8 +1261,7 @@ interface nsINavHistoryService : nsISupports /** * Gets an array of registered nsINavHistoryObserver objects. */ - void getObservers([optional] out unsigned long count, - [retval, array, size_is(count)] out nsINavHistoryObserver observers); + Array getObservers(); /** * True if history is disabled. currently, diff --git a/toolkit/components/places/nsNavBookmarks.cpp b/toolkit/components/places/nsNavBookmarks.cpp index 1e3f59959383..910cac6ba811 100644 --- a/toolkit/components/places/nsNavBookmarks.cpp +++ b/toolkit/components/places/nsNavBookmarks.cpp @@ -1763,30 +1763,20 @@ nsNavBookmarks::RemoveObserver(nsINavBookmarkObserver* aObserver) { } NS_IMETHODIMP -nsNavBookmarks::GetObservers(uint32_t* _count, - nsINavBookmarkObserver*** _observers) { - NS_ENSURE_ARG_POINTER(_count); - NS_ENSURE_ARG_POINTER(_observers); - - *_count = 0; - *_observers = nullptr; +nsNavBookmarks::GetObservers(nsTArray>& aObservers) { + aObservers.Clear(); if (!mCanNotify) return NS_OK; - nsCOMArray observers; - for (uint32_t i = 0; i < mObservers.Length(); ++i) { - const nsCOMPtr& observer = + nsCOMPtr observer = mObservers.ElementAt(i).GetValue(); // Skip nullified weak observers. - if (observer) observers.AppendElement(observer); + if (observer) { + aObservers.AppendElement(observer.forget()); + } } - if (observers.Count() == 0) return NS_OK; - - *_count = observers.Count(); - observers.Forget(_observers); - return NS_OK; } diff --git a/toolkit/components/places/nsNavHistory.cpp b/toolkit/components/places/nsNavHistory.cpp index b7287a03b541..3037008f7417 100644 --- a/toolkit/components/places/nsNavHistory.cpp +++ b/toolkit/components/places/nsNavHistory.cpp @@ -2025,13 +2025,8 @@ nsNavHistory::RemoveObserver(nsINavHistoryObserver* aObserver) { } NS_IMETHODIMP -nsNavHistory::GetObservers(uint32_t* _count, - nsINavHistoryObserver*** _observers) { - NS_ENSURE_ARG_POINTER(_count); - NS_ENSURE_ARG_POINTER(_observers); - - *_count = 0; - *_observers = nullptr; +nsNavHistory::GetObservers(nsTArray>& aObservers) { + aObservers.Clear(); // Clear any cached value, cause it's very likely the consumer has made // changes to history and is now trying to notify them. @@ -2039,21 +2034,16 @@ nsNavHistory::GetObservers(uint32_t* _count, if (!mCanNotify) return NS_OK; - nsCOMArray observers; - // Then add the other observers. for (uint32_t i = 0; i < mObservers.Length(); ++i) { - const nsCOMPtr& observer = + nsCOMPtr observer = mObservers.ElementAt(i).GetValue(); // Skip nullified weak observers. - if (observer) observers.AppendElement(observer); + if (observer) { + aObservers.AppendElement(observer.forget()); + } } - if (observers.Count() == 0) return NS_OK; - - *_count = observers.Count(); - observers.Forget(_observers); - return NS_OK; }