Bug 1314084 - Implement `nsIAnnotationService::getObservers`. r?mak
MozReview-Commit-ID: 42y8d1fbfJO
--- a/toolkit/components/places/nsAnnotationService.cpp
+++ b/toolkit/components/places/nsAnnotationService.cpp
@@ -1668,16 +1668,37 @@ nsAnnotationService::RemoveObserver(nsIA
{
NS_ENSURE_ARG(aObserver);
if (!mObservers.RemoveObject(aObserver))
return NS_ERROR_INVALID_ARG;
return NS_OK;
}
+NS_IMETHODIMP
+nsAnnotationService::GetObservers(uint32_t* _count,
+ nsIAnnotationObserver*** _observers)
+{
+ NS_ENSURE_ARG_POINTER(_count);
+ NS_ENSURE_ARG_POINTER(_observers);
+
+ *_count = 0;
+ *_observers = nullptr;
+
+ nsCOMArray<nsIAnnotationObserver> observers(mObservers);
+
+ if (observers.Count() == 0)
+ return NS_OK;
+
+ *_count = observers.Count();
+ observers.Forget(_observers);
+
+ return NS_OK;
+}
+
nsresult
nsAnnotationService::HasAnnotationInternal(nsIURI* aURI,
int64_t aItemId,
const nsACString& aName,
bool* _hasAnno)
{
bool isItemAnnotation = (aItemId > 0);
nsCOMPtr<mozIStorageStatement> stmt;
--- a/toolkit/components/places/nsIAnnotationService.idl
+++ b/toolkit/components/places/nsIAnnotationService.idl
@@ -373,16 +373,22 @@ interface nsIAnnotationService : nsISupp
*/
void addObserver(in nsIAnnotationObserver aObserver);
/**
* Removes an annotaton observer previously registered by addObserver.
*/
void removeObserver(in nsIAnnotationObserver aObserver);
+
+ /**
+ * Gets an array of registered nsIAnnotationObserver objects.
+ */
+ void getObservers([optional] out unsigned long count,
+ [retval, array, size_is(count)] out nsIAnnotationObserver observers);
};
/**
* Represents a place annotated with a given annotation. If a place has
* multiple annotations, it can be represented by multiple
* mozIAnnotatedResult(s).
*/
[scriptable, uuid(81fd0188-db6a-492e-80b6-f6414913b396)]
--- a/toolkit/components/places/tests/unit/test_null_interfaces.js
+++ b/toolkit/components/places/tests/unit/test_null_interfaces.js
@@ -14,17 +14,17 @@ var testServices = [
["queryStringToQueries", "removePagesByTimeframe", "removePagesFromHost", "getObservers"]
],
["browser/nav-bookmarks-service;1",
["nsINavBookmarksService", "nsINavHistoryObserver", "nsIAnnotationObserver"],
["createFolder", "getObservers", "onFrecencyChanged", "onTitleChanged",
"onPageAnnotationSet", "onPageAnnotationRemoved"]
],
["browser/livemark-service;2", ["mozIAsyncLivemarks"], ["reloadLivemarks"]],
- ["browser/annotation-service;1", ["nsIAnnotationService"], []],
+ ["browser/annotation-service;1", ["nsIAnnotationService"], ["getObservers"]],
["browser/favicon-service;1", ["nsIFaviconService"], []],
["browser/tagging-service;1", ["nsITaggingService"], []],
];
do_print(testServices.join("\n"));
function run_test()
{
for (let [cid, ifaces, nothrow] of testServices) {