Bug 1274108 - Expose annotation service observers.
MozReview-Commit-ID: Bw78EbUbFkb
--- a/toolkit/components/places/nsAnnotationService.cpp
+++ b/toolkit/components/places/nsAnnotationService.cpp
@@ -146,16 +146,41 @@ nsAnnotationService::Init()
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
if (obsSvc) {
(void)obsSvc->AddObserver(this, TOPIC_PLACES_SHUTDOWN, true);
}
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;
+
+ if (mObservers.Count() == 0)
+ return NS_OK;
+
+ *_observers = static_cast<nsIAnnotationObserver**>
+ (moz_xmalloc(mObservers.Count() * sizeof(nsIAnnotationObserver*)));
+ NS_ENSURE_TRUE(*_observers, NS_ERROR_OUT_OF_MEMORY);
+
+ *_count = mObservers.Count();
+ for (uint32_t i = 0; i < *_count; ++i) {
+ NS_ADDREF((*_observers)[i] = mObservers[i]);
+ }
+
+ return NS_OK;
+}
+
nsresult
nsAnnotationService::SetAnnotationStringInternal(nsIURI* aURI,
int64_t aItemId,
const nsACString& aName,
const nsAString& aValue,
int32_t aFlags,
uint16_t aExpiration)
{
--- a/toolkit/components/places/nsIAnnotationService.idl
+++ b/toolkit/components/places/nsIAnnotationService.idl
@@ -359,16 +359,19 @@ interface nsIAnnotationService : nsISupp
*/
void addObserver(in nsIAnnotationObserver aObserver);
/**
* Removes an annotaton observer previously registered by addObserver.
*/
void removeObserver(in nsIAnnotationObserver aObserver);
+
+ 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
@@ -15,17 +15,17 @@ var testServices = [
"removeVisitsByTimeframe", "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) {