var BookmarkHelper = { _panel: null, _editor: null, edit: function BH_edit(aURI) { if (!aURI) aURI = getBrowser().currentURI; let itemId = PlacesUtils.getMostRecentBookmarkForURI(aURI); if (itemId == -1) return; let title = PlacesUtils.bookmarks.getItemTitle(itemId); let tags = PlacesUtils.tagging.getTagsForURI(aURI, {}); const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; this._editor = document.createElementNS(XULNS, "placeitem"); this._editor.setAttribute("id", "bookmark-item"); this._editor.setAttribute("flex", "1"); this._editor.setAttribute("type", "bookmark"); this._editor.setAttribute("ui", "manage"); this._editor.setAttribute("title", title); this._editor.setAttribute("uri", aURI.spec); this._editor.setAttribute("itemid", itemId); this._editor.setAttribute("tags", tags.join(", ")); this._editor.setAttribute("onclose", "BookmarkHelper.hide()"); document.getElementById("bookmark-form").appendChild(this._editor); let toolbar = document.getElementById("toolbar-main"); let top = toolbar.top + toolbar.boxObject.height; this._panel = document.getElementById("bookmark-container"); this._panel.top = (top < 0 ? 0 : top); this._panel.hidden = false; BrowserUI.pushPopup(this, this._panel); let self = this; BrowserUI.lockToolbar(); Browser.forceChromeReflow(); self._editor.startEditing(); }, save: function BH_save() { this._editor.stopEditing(true); }, hide: function BH_hide() { BrowserUI.unlockToolbar(); BrowserUI.updateStar(); // Note: the _editor will have already saved the data, if needed, by the time // this method is called, since this method is called via the "close" event. this._editor.parentNode.removeChild(this._editor); this._editor = null; this._panel.hidden = true; BrowserUI.popPopup(this); }, removeBookmarksForURI: function BH_removeBookmarksForURI(aURI) { //XXX blargle xpconnect! might not matter, but a method on // nsINavBookmarksService that takes an array of items to // delete would be faster. better yet, a method that takes a URI! let itemIds = PlacesUtils.getBookmarksForURI(aURI); itemIds.forEach(PlacesUtils.bookmarks.removeItem); BrowserUI.updateStar(); } };