Bug 1274108 - Expose annotation service observers. draft
authorKit Cambridge <kcambridge@mozilla.com>
Fri, 03 Jun 2016 11:15:30 -0700
changeset 375299 4384b8de2b3aa506150ea72cdcb15dff7a829edd
parent 375298 fbd10c11ef72925d542962673b3ba77a72ceeb0f
child 375300 5d3982be429442a41785a5d8a0bfe555d4b36efa
push id20219
push userkcambridge@mozilla.com
push dateFri, 03 Jun 2016 21:20:40 +0000
bugs1274108
milestone49.0a1
Bug 1274108 - Expose annotation service observers. MozReview-Commit-ID: Bw78EbUbFkb
toolkit/components/places/nsAnnotationService.cpp
toolkit/components/places/nsIAnnotationService.idl
toolkit/components/places/tests/unit/test_null_interfaces.js
--- 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) {