Bug 1362863 - Do not fire bookmarks.onCreated for bookmarks automatically created for the Library window, r?mak r?mixedpuppy draft
authorBob Silverberg <bsilverberg@mozilla.com>
Fri, 11 Aug 2017 07:26:16 -0400
changeset 673753 2e4fe9303d3fa637ce636a7ce1e9b0a2ecbc57e7
parent 673329 97efdde466f18cf580fda9673cf4c38ee21fc7b7
child 734137 af3c9e61e2d1df1f57aa4981e8faadd691da89e7
push id82631
push userbmo:bob.silverberg@gmail.com
push dateMon, 02 Oct 2017 18:39:01 +0000
reviewersmak, mixedpuppy
bugs1362863
milestone58.0a1
Bug 1362863 - Do not fire bookmarks.onCreated for bookmarks automatically created for the Library window, r?mak r?mixedpuppy This ignores the onItemAdded event from nsINavBookmarkObserver for any bookmarks that are automatically created for the Library window. MozReview-Commit-ID: ELdwmr6eItT
browser/components/extensions/ext-bookmarks.js
--- a/browser/components/extensions/ext-bookmarks.js
+++ b/browser/components/extensions/ext-bookmarks.js
@@ -2,16 +2,18 @@
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 // The ext-* files are imported into the same scopes.
 /* import-globals-from ext-browserAction.js */
 
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
                                   "resource://gre/modules/PlacesUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesUIUtils",
+                                  "resource:///modules/PlacesUIUtils.jsm");
 
 const {
   TYPE_BOOKMARK,
   TYPE_FOLDER,
   TYPE_SEPARATOR,
 } = PlacesUtils.bookmarks;
 
 const BOOKMARKS_TYPES_TO_API_TYPES_MAP = new Map([
@@ -111,22 +113,32 @@ const convertBookmarks = result => {
 };
 
 let observer = new class extends EventEmitter {
   constructor() {
     super();
 
     this.skipTags = true;
     this.skipDescendantsOnItemRemoval = true;
+    this.ignoreOnItemAdded = true;
+    this.virtualFolderIds = [PlacesUIUtils.leftPaneFolderId, PlacesUIUtils.allBookmarksFolderId];
+    this.ignoreOnItemAdded = false;
   }
 
   onBeginUpdateBatch() {}
   onEndUpdateBatch() {}
 
   onItemAdded(id, parentId, index, itemType, uri, title, dateAdded, guid, parentGuid, source) {
+    // Ignore Firefox's internal library folders.
+    if (this.ignoreOnItemAdded
+        || this.virtualFolderIds.includes(id)
+        || this.virtualFolderIds.includes(parentId)) {
+      return;
+    }
+
     let bookmark = {
       id: guid,
       parentId: parentGuid,
       index,
       title,
       dateAdded: dateAdded / 1000,
       type: BOOKMARKS_TYPES_TO_API_TYPES_MAP.get(itemType),
       url: getUrl(itemType, uri && uri.spec),