--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -5,26 +5,28 @@
// This file is loaded into the browser window scope.
/* eslint-env mozilla/browser-window */
XPCOMUtils.defineLazyScriptGetter(this, ["PlacesToolbar", "PlacesMenu",
"PlacesPanelview", "PlacesPanelMenuView"],
"chrome://browser/content/places/browserPlacesViews.js");
var StarUI = {
- _itemId: -1,
- uri: null,
+ _itemGuids: null,
+ // TODO (bug 1131491): _itemIdsMap is only used for the old transactions manager.
+ _itemIdsMap: null,
_batching: false,
_isNewBookmark: false,
_isComposing: false,
_autoCloseTimer: 0,
// The autoclose timer is diasbled if the user interacts with the
// popup, such as making a change through typing or clicking on
// the popup.
_autoCloseTimerEnabled: true,
+ _removeBookmarksOnPopupHidden: false,
_element(aID) {
return document.getElementById(aID);
},
// Edit-bookmark panel
get panel() {
delete this.panel;
@@ -98,42 +100,50 @@ var StarUI = {
if (!this._element("editBookmarkPanelContent").hidden)
this.quitEditMode();
if (this._anchorToolbarButton) {
this._anchorToolbarButton.removeAttribute("open");
this._anchorToolbarButton = null;
}
this._restoreCommandsState();
- this._itemId = -1;
- if (this._batching)
+ let removeBookmarksOnPopupHidden = this._removeBookmarksOnPopupHidden;
+ this._removeBookmarksOnPopupHidden = false;
+ let idsForRemoval = this._itemIdsMap;
+ let guidsForRemoval = this._itemGuids;
+ this._itemGuids = null;
+ this._itemIdsMap = null;
+
+ if (this._batching) {
this.endBatch();
+ }
let libraryButton;
- if (this._uriForRemoval) {
+ if (removeBookmarksOnPopupHidden && guidsForRemoval) {
if (this._isNewBookmark) {
if (!PlacesUIUtils.useAsyncTransactions) {
PlacesUtils.transactionManager.undoTransaction();
break;
}
PlacesTransactions.undo().catch(Cu.reportError);
break;
}
// Remove all bookmarks for the bookmark's url, this also removes
// the tags for the url.
if (!PlacesUIUtils.useAsyncTransactions) {
- let itemIds = PlacesUtils.getBookmarksForURI(this._uriForRemoval);
- for (let itemId of itemIds) {
- let txn = new PlacesRemoveItemTransaction(itemId);
- PlacesUtils.transactionManager.doTransaction(txn);
+ if (idsForRemoval) {
+ for (let itemId of idsForRemoval.values()) {
+ let txn = new PlacesRemoveItemTransaction(itemId);
+ PlacesUtils.transactionManager.doTransaction(txn);
+ }
}
break;
}
- PlacesTransactions.RemoveBookmarksForUrls([this._uriForRemoval])
+ PlacesTransactions.Remove(guidsForRemoval)
.transact().catch(Cu.reportError);
} else if (this._isNewBookmark &&
Services.prefs.getBoolPref("toolkit.cosmeticAnimations.enabled") &&
AppConstants.MOZ_PHOTON_ANIMATIONS &&
(libraryButton = document.getElementById("library-button")) &&
libraryButton.getAttribute("cui-areatype") != "menu-panel" &&
libraryButton.getAttribute("overflowedItem") != "true" &&
libraryButton.closest("#nav-bar")) {
@@ -236,32 +246,33 @@ var StarUI = {
// Slow double-clicks (not true double-clicks) shouldn't
// cause the panel to flicker.
if (this.panel.state == "showing" ||
this.panel.state == "open") {
return;
}
this._isNewBookmark = aIsNewBookmark;
- this._uriForRemoval = "";
+ this._itemIdsMap = null;
+ this._itemGuids = null;
// TODO (bug 1131491): Deprecate this once async transactions are enabled
// and the legacy transactions code is gone.
if (typeof(aNode) == "number") {
let itemId = aNode;
let guid = await PlacesUtils.promiseItemGuid(itemId);
aNode = await PlacesUIUtils.fetchNodeLike(guid);
}
// Performance: load the overlay the first time the panel is opened
// (see bug 392443).
if (this._overlayLoading)
return;
if (this._overlayLoaded) {
- this._doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition);
+ await this._doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition);
return;
}
this._overlayLoading = true;
document.loadOverlay(
"chrome://browser/content/places/editBookmarkOverlay.xul",
(aSubject, aTopic, aData) => {
// Move the header (star, title, button) into the grid,
@@ -273,17 +284,17 @@ var StarUI = {
this._overlayLoading = false;
this._overlayLoaded = true;
this._doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition);
}
);
},
- _doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition) {
+ async _doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition) {
if (this.panel.state != "closed")
return;
this._blockCommands(); // un-done in the popuphidden handler
this._element("editBookmarkPanelTitle").value =
this._isNewBookmark ?
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
@@ -291,25 +302,33 @@ var StarUI = {
// No description; show the Done, Remove;
this._element("editBookmarkPanelDescription").textContent = "";
this._element("editBookmarkPanelBottomButtons").hidden = false;
this._element("editBookmarkPanelContent").hidden = false;
// The label of the remove button differs if the URI is bookmarked
// multiple times.
- let bookmarks = PlacesUtils.getBookmarksForURI(gBrowser.currentURI);
+ this._itemGuids = [];
+
+ await PlacesUtils.bookmarks.fetch({url: gBrowser.currentURI},
+ bookmark => this._itemGuids.push(bookmark.guid));
+
+ if (!PlacesUIUtils.useAsyncTransactions) {
+ this._itemIdsMap = await PlacesUtils.promiseManyItemIds(this._itemGuids);
+ }
let forms = gNavigatorBundle.getString("editBookmark.removeBookmarks.label");
- let label = PluralForm.get(bookmarks.length, forms).replace("#1", bookmarks.length);
+ let bookmarksCount = this._itemGuids.length;
+ let label = PluralForm.get(bookmarksCount, forms)
+ .replace("#1", bookmarksCount);
this._element("editBookmarkPanelRemoveButton").label = label;
// unset the unstarred state, if set
this._element("editBookmarkPanelStarIcon").removeAttribute("unstarred");
- this._itemId = aNode.itemId;
this.beginBatch();
if (aAnchorElement) {
// Set the open=true attribute if the anchor is a
// descendent of a toolbarbutton.
let parent = aAnchorElement.parentNode;
while (parent) {
if (parent.localName == "toolbarbutton") {
@@ -356,17 +375,17 @@ var StarUI = {
quitEditMode: function SU_quitEditMode() {
this._element("editBookmarkPanelContent").hidden = true;
this._element("editBookmarkPanelBottomButtons").hidden = true;
gEditItemOverlay.uninitPanel(true);
},
removeBookmarkButtonCommand: function SU_removeBookmarkButtonCommand() {
- this._uriForRemoval = PlacesUtils.bookmarks.getBookmarkURI(this._itemId);
+ this._removeBookmarksOnPopupHidden = true;
this.panel.hidePopup();
},
// Matching the way it is used in the Library, editBookmarkOverlay implements
// an instant-apply UI, having no batched-Undo/Redo support.
// However, in this context (the Star UI) we have a Cancel button whose
// expected behavior is to undo all the operations done in the panel.
// Sometime in the future this needs to be reimplemented using a