Bug 1361797 - Migrate History/Bookmark observers to system add-on draft bug1361797
authork88hudson <khudson@mozilla.com>
Wed, 03 May 2017 14:32:47 -0400
changeset 572084 497b1c16604d24c328e51cd10c0228d7d087fd36
parent 570861 076a7a66096f9e8d102548397254be32eb26bc3d
child 626947 1313d72cd5ac2431e93a3b594ae9eeb442086203
push id56993
push userkhudson@mozilla.com
push dateWed, 03 May 2017 18:33:11 +0000
bugs1361797
milestone55.0a1
Bug 1361797 - Migrate History/Bookmark observers to system add-on 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) {