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
--- 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),