Bug 1361797 - Migrate History/Bookmark observers to system add-on r=ursula
authork88hudson <khudson@mozilla.com>
Wed, 03 May 2017 14:32:47 -0400
changeset 573149 5510b2c782088b5040df1132fbc06c55cf5a9117
parent 573148 b06d3343f43a1ceacf22293e5a3650195a6211fc
child 573150 9267221b3d8435942eddb0d73fb70bcc4ec82a9a
push id57306
push userbmo:emilio+bugs@crisal.io
push dateFri, 05 May 2017 10:08:55 +0000
reviewersursula
bugs1361797
milestone55.0a1
Bug 1361797 - Migrate History/Bookmark observers to system add-on r=ursula MozReview-Commit-ID: 2qK24pez8MZ
toolkit/modules/NewTabUtils.jsm
--- a/toolkit/modules/NewTabUtils.jsm
+++ b/toolkit/modules/NewTabUtils.jsm
@@ -923,92 +923,16 @@ var ActivityStreamProvider = {
       } catch (e) {
         link.eTLD = "";
       }
       return link;
     });
   },
 
   /*
-   * Initializes Activity Stream provider - adds a history observer and a
-   * bookmarks observer.
-   */
-  init() {
-    PlacesUtils.history.addObserver(this.historyObserver, true);
-    PlacesUtils.bookmarks.addObserver(this.bookmarksObsever, true);
-  },
-
-  /**
-   * A set of functions called by @mozilla.org/browser/nav-historyservice
-   * All history events are emitted from this object.
-   */
-  historyObserver: {
-    onDeleteURI(uri) {
-      Services.obs.notifyObservers(null, "newtab-deleteURI", {url: uri.spec});
-    },
-
-    onClearHistory() {
-      Services.obs.notifyObservers(null, "newtab-clearHistory");
-    },
-
-    onFrecencyChanged(uri, newFrecency, guid, hidden, lastVisitDate) {
-      if (!hidden && lastVisitDate) {
-        Services.obs.notifyObservers(null, "newtab-linkChanged", {
-          url: uri.spec,
-          frecency: newFrecency,
-          lastVisitDate,
-          type: "history"
-        });
-      }
-    },
-
-    onManyFrecenciesChanged() {
-      Services.obs.notifyObservers(null, "newtab-manyLinksChanged");
-    },
-
-    onTitleChanged(uri, newTitle) {
-      Services.obs.notifyObservers(null, "newtab-linkChanged", {url: uri.spec, title: newTitle});
-    },
-
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryObserver,
-                                           Ci.nsISupportsWeakReference])
-  },
-
-  /**
-   * A set of functions called by @mozilla.org/browser/nav-bookmarks-service
-   * All bookmark events are emitted from this object.
-   */
-  bookmarksObsever: {
-    onItemAdded(id, folderId, index, type, uri, title, dateAdded, guid) {
-      if (type === PlacesUtils.bookmarks.TYPE_BOOKMARK) {
-        ActivityStreamProvider.getBookmark(guid).then(bookmark => {
-          Services.obs.notifyObservers(null, "newtab-bookmarkAdded", bookmark);
-        }).catch(Cu.reportError);
-      }
-    },
-
-    onItemRemoved(id, folderId, index, type, uri) {
-      if (type === PlacesUtils.bookmarks.TYPE_BOOKMARK) {
-        Services.obs.notifyObservers(null, "newtab-bookmarkRemoved", {bookmarkId: id, url: uri.spec});
-      }
-    },
-
-    onItemChanged(id, property, isAnnotation, value, lastModified, type, parent, guid) {
-      if (type === PlacesUtils.bookmarks.TYPE_BOOKMARK) {
-        ActivityStreamProvider.getBookmark(guid).then(bookmark => {
-          Services.obs.notifyObservers(null, "newtab-bookmarkChanged", bookmark);
-        }).catch(Cu.reportError);
-      }
-    },
-
-    QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver,
-                                           Ci.nsISupportsWeakReference])
-  },
-
-  /*
    * Gets the top frecent sites for Activity Stream.
    *
    * @param {Object} aOptions
    *          options.ignoreBlocked: Do not filter out blocked links .
    *
    * @returns {Promise} Returns a promise with the array of links as payload.
    */
   getTopFrecentSites: Task.async(function*(aOptions = {}) {
@@ -1167,17 +1091,17 @@ var ActivityStreamLinks = {
    * @param {Object} aLink
    *          The link which contains a URL to add to the block list
    */
   blockURL(aLink) {
     BlockedLinks.block(aLink);
   },
 
   onLinkBlocked(aLink) {
-    Services.obs.notifyObservers(null, "newtab-linkChanged", {url: aLink.url, blocked: true})
+    Services.obs.notifyObservers(null, "newtab-linkBlocked", aLink.url);
   },
 
   /**
    * Adds a bookmark
    *
    * @param {String} aUrl
    *          The url to bookmark
    *
@@ -1838,17 +1762,16 @@ this.NewTabUtils = {
 
     // Strip off common subdomains of the same site (e.g., www, load balancer)
     return host.replace(/^(m|mobile|www\d*)\./, "");
   },
 
   init: function NewTabUtils_init() {
     if (this.initWithoutProviders()) {
       PlacesProvider.init();
-      ActivityStreamProvider.init();
       Links.addProvider(PlacesProvider);
       BlockedLinks.addObserver(Links);
       BlockedLinks.addObserver(ActivityStreamLinks);
     }
   },
 
   initWithoutProviders: function NewTabUtils_initWithoutProviders() {
     if (!this._initialized) {