2012-05-30 20:48:24 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-08-09 00:06:47 +04:00
|
|
|
|
2019-01-30 00:21:26 +03:00
|
|
|
var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2018-02-03 21:49:47 +03:00
|
|
|
|
|
|
|
XPCOMUtils.defineLazyScriptGetter(this, ["PlacesToolbar", "PlacesMenu",
|
|
|
|
"PlacesPanelview", "PlacesPanelMenuView"],
|
|
|
|
"chrome://communicator/content/places/browserPlacesViews.js");
|
|
|
|
|
2010-08-09 00:06:47 +04:00
|
|
|
var StarUI = {
|
2018-04-24 20:29:31 +03:00
|
|
|
_itemGuids: null,
|
2010-08-09 00:06:47 +04:00
|
|
|
uri: null,
|
|
|
|
_batching: false,
|
|
|
|
|
|
|
|
_element: function(aID) {
|
|
|
|
return document.getElementById(aID);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Edit-bookmark panel
|
|
|
|
get panel() {
|
|
|
|
delete this.panel;
|
|
|
|
var element = this._element("editBookmarkPanel");
|
|
|
|
// initially the panel is hidden
|
|
|
|
// to avoid impacting startup / new window performance
|
|
|
|
element.hidden = false;
|
2017-11-19 12:54:55 +03:00
|
|
|
element.addEventListener("popuphidden", this);
|
|
|
|
element.addEventListener("keypress", this);
|
2018-02-03 21:49:47 +03:00
|
|
|
element.addEventListener("keypress", this);
|
|
|
|
element.addEventListener("mousedown", this);
|
|
|
|
element.addEventListener("mouseout", this);
|
|
|
|
element.addEventListener("mousemove", this);
|
|
|
|
element.addEventListener("compositionstart", this);
|
|
|
|
element.addEventListener("compositionend", this);
|
|
|
|
element.addEventListener("input", this);
|
|
|
|
element.addEventListener("popuphidden", this);
|
|
|
|
element.addEventListener("popupshown", this);
|
2010-08-09 00:06:47 +04:00
|
|
|
return this.panel = element;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Array of command elements to disable when the panel is opened.
|
|
|
|
get _blockedCommands() {
|
|
|
|
delete this._blockedCommands;
|
|
|
|
return this._blockedCommands =
|
2015-04-15 22:11:49 +03:00
|
|
|
["cmd_close", "cmd_closeWindow"].map(id => this._element(id));
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_blockCommands: function SU__blockCommands() {
|
|
|
|
this._blockedCommands.forEach(function (elt) {
|
|
|
|
// make sure not to permanently disable this item (see bug 409155)
|
|
|
|
if (elt.hasAttribute("wasDisabled"))
|
|
|
|
return;
|
|
|
|
if (elt.getAttribute("disabled") == "true") {
|
|
|
|
elt.setAttribute("wasDisabled", "true");
|
|
|
|
} else {
|
|
|
|
elt.setAttribute("wasDisabled", "false");
|
|
|
|
elt.setAttribute("disabled", "true");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_restoreCommandsState: function SU__restoreCommandsState() {
|
|
|
|
this._blockedCommands.forEach(function (elt) {
|
|
|
|
if (elt.getAttribute("wasDisabled") != "true")
|
|
|
|
elt.removeAttribute("disabled");
|
|
|
|
elt.removeAttribute("wasDisabled");
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2023-11-16 01:53:25 +03:00
|
|
|
// EventListener
|
2010-08-09 00:06:47 +04:00
|
|
|
handleEvent: function SU_handleEvent(aEvent) {
|
|
|
|
switch (aEvent.type) {
|
|
|
|
case "popuphidden":
|
|
|
|
if (aEvent.originalTarget == this.panel) {
|
|
|
|
if (!this._element("editBookmarkPanelContent").hidden)
|
|
|
|
this.quitEditMode();
|
|
|
|
|
|
|
|
this._restoreCommandsState();
|
2018-04-24 20:29:31 +03:00
|
|
|
let guidsForRemoval = this._itemGuids;
|
|
|
|
this._itemGuids = null;
|
|
|
|
|
2010-08-09 00:06:47 +04:00
|
|
|
if (this._batching) {
|
2018-04-24 20:29:31 +03:00
|
|
|
this.endBatch();
|
2010-08-09 00:06:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (this._actionOnHide) {
|
|
|
|
case "cancel": {
|
2018-04-24 20:29:31 +03:00
|
|
|
PlacesTransactions.undo().catch(Cu.reportError);
|
2010-08-09 00:06:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "remove": {
|
2018-04-24 20:29:31 +03:00
|
|
|
PlacesTransactions.Remove(guidsForRemoval)
|
|
|
|
.transact().catch(Cu.reportError);
|
2010-08-09 00:06:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._actionOnHide = "";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "keypress":
|
2011-12-19 16:59:38 +04:00
|
|
|
if (aEvent.defaultPrevented) {
|
2010-08-09 00:06:47 +04:00
|
|
|
// The event has already been consumed inside of the panel.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (aEvent.keyCode) {
|
|
|
|
case KeyEvent.DOM_VK_ESCAPE:
|
|
|
|
if (!this._element("editBookmarkPanelContent").hidden)
|
|
|
|
this.cancelButtonOnCommand();
|
|
|
|
break;
|
|
|
|
case KeyEvent.DOM_VK_RETURN:
|
|
|
|
if (aEvent.target.className == "expander-up" ||
|
|
|
|
aEvent.target.className == "expander-down" ||
|
|
|
|
aEvent.target.id == "editBMPanel_newFolderButton") {
|
2011-12-19 16:59:38 +04:00
|
|
|
//XXX Why is this necessary? The defaultPrevented check should
|
2010-08-09 00:06:47 +04:00
|
|
|
// be enough.
|
|
|
|
break;
|
|
|
|
}
|
2018-04-24 20:29:31 +03:00
|
|
|
this.panel.hidePopup(true);
|
2010-08-09 00:06:47 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_overlayLoaded: false,
|
|
|
|
_overlayLoading: false,
|
2018-04-24 20:29:31 +03:00
|
|
|
async showEditBookmarkPopup(aNode, aAnchorElement, aPosition, aIsNewBookmark, aUrl) {
|
2018-02-03 21:49:47 +03:00
|
|
|
// 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 = "";
|
2018-04-24 20:29:31 +03:00
|
|
|
this._itemGuids = null;
|
2018-02-03 21:49:47 +03:00
|
|
|
|
2010-08-09 00:06:47 +04:00
|
|
|
// Performance: load the overlay the first time the panel is opened
|
|
|
|
// (see bug 392443).
|
|
|
|
if (this._overlayLoading)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._overlayLoaded) {
|
2018-04-24 20:29:31 +03:00
|
|
|
await this._doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition, aUrl);
|
2010-08-09 00:06:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._overlayLoading = true;
|
2012-06-17 19:40:54 +04:00
|
|
|
document.loadOverlay(
|
2018-02-03 21:49:47 +03:00
|
|
|
"chrome://communicator/content/places/editBookmarkOverlay.xul",
|
|
|
|
(aSubject, aTopic, aData) => {
|
2012-06-17 19:40:54 +04:00
|
|
|
// Move the header (star, title, button) into the grid,
|
|
|
|
// so that it aligns nicely with the other items (bug 484022).
|
|
|
|
let header = this._element("editBookmarkPanelHeader");
|
|
|
|
let rows = this._element("editBookmarkPanelGrid").lastChild;
|
|
|
|
rows.insertBefore(header, rows.firstChild);
|
|
|
|
header.hidden = false;
|
|
|
|
|
|
|
|
this._overlayLoading = false;
|
|
|
|
this._overlayLoaded = true;
|
2018-04-24 20:29:31 +03:00
|
|
|
this._doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition, aUrl);
|
2018-02-03 21:49:47 +03:00
|
|
|
}
|
2012-06-17 19:40:54 +04:00
|
|
|
);
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
2018-04-24 20:29:31 +03:00
|
|
|
async _doShowEditBookmarkPanel(aNode, aAnchorElement, aPosition, aUrl) {
|
2010-08-09 00:06:47 +04:00
|
|
|
if (this.panel.state != "closed")
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._blockCommands(); // un-done in the popuphiding handler
|
|
|
|
|
|
|
|
// Set panel title:
|
|
|
|
// if we are batching, i.e. the bookmark has been added now,
|
|
|
|
// then show Page Bookmarked, else if the bookmark did already exist,
|
|
|
|
// we are about editing it, then use Edit This Bookmark.
|
|
|
|
this._element("editBookmarkPanelTitle").value =
|
2018-02-03 21:49:47 +03:00
|
|
|
this._isNewBookmark ?
|
2010-08-09 00:06:47 +04:00
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.pageBookmarkedTitle") :
|
|
|
|
gNavigatorBundle.getString("editBookmarkPanel.editBookmarkTitle");
|
|
|
|
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = false;
|
|
|
|
this._element("editBookmarkPanelContent").hidden = false;
|
|
|
|
|
|
|
|
// The label of the remove button differs if the URI is bookmarked
|
|
|
|
// multiple times.
|
2018-04-24 20:29:31 +03:00
|
|
|
this._itemGuids = [];
|
|
|
|
|
|
|
|
await PlacesUtils.bookmarks.fetch({url: aUrl},
|
|
|
|
bookmark => this._itemGuids.push(bookmark.guid));
|
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
let forms = gNavigatorBundle.getString("editBookmark.removeBookmarks.label");
|
2018-04-24 20:29:31 +03:00
|
|
|
let bookmarksCount = this._itemGuids.length;
|
|
|
|
let label = PluralForm.get(bookmarksCount, forms)
|
|
|
|
.replace("#1", bookmarksCount);
|
2010-08-09 00:06:47 +04:00
|
|
|
this._element("editBookmarkPanelRemoveButton").label = label;
|
|
|
|
|
|
|
|
this.beginBatch();
|
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
let onPanelReady = fn => {
|
|
|
|
let target = this.panel;
|
|
|
|
if (target.parentNode) {
|
|
|
|
// By targeting the panel's parent and using a capturing listener, we
|
|
|
|
// can have our listener called before others waiting for the panel to
|
|
|
|
// be shown (which probably expect the panel to be fully initialized)
|
|
|
|
target = target.parentNode;
|
|
|
|
}
|
|
|
|
target.addEventListener("popupshown", function(event) {
|
|
|
|
fn();
|
|
|
|
}, {"capture": true, "once": true});
|
|
|
|
};
|
|
|
|
gEditItemOverlay.initPanel({ node: aNode,
|
|
|
|
onPanelReady,
|
|
|
|
hiddenRows: ["description", "location",
|
|
|
|
"loadInSidebar", "keyword"],
|
|
|
|
focusedElement: "preferred"});
|
|
|
|
this.panel.openPopup(aAnchorElement, aPosition);
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
panelShown:
|
|
|
|
function SU_panelShown(aEvent) {
|
|
|
|
if (aEvent.target == this.panel) {
|
|
|
|
if (!this._element("editBookmarkPanelContent").hidden) {
|
|
|
|
let fieldToFocus = "editBMPanel_" +
|
|
|
|
Services.prefs.getCharPref("browser.bookmarks.editDialog.firstEditField");
|
|
|
|
var elt = this._element(fieldToFocus);
|
|
|
|
elt.focus();
|
|
|
|
elt.select();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Note this isn't actually used anymore, we should remove this
|
|
|
|
// once we decide not to bring back the page bookmarked notification
|
|
|
|
this.panel.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
quitEditMode: function SU_quitEditMode() {
|
|
|
|
this._element("editBookmarkPanelContent").hidden = true;
|
|
|
|
this._element("editBookmarkPanelBottomButtons").hidden = true;
|
|
|
|
gEditItemOverlay.uninitPanel(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
editButtonCommand: function SU_editButtonCommand() {
|
|
|
|
this.showEditBookmarkPopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelButtonOnCommand: function SU_cancelButtonOnCommand() {
|
|
|
|
this._actionOnHide = "cancel";
|
|
|
|
this.panel.hidePopup();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeBookmarkButtonCommand: function SU_removeBookmarkButtonCommand() {
|
2018-04-24 20:29:31 +03:00
|
|
|
this._removeBookmarksOnPopupHidden = true;
|
2010-08-09 00:06:47 +04:00
|
|
|
this._actionOnHide = "remove";
|
|
|
|
this.panel.hidePopup();
|
|
|
|
},
|
|
|
|
|
2018-04-24 20:29:31 +03:00
|
|
|
_batchBlockingDeferred: null,
|
|
|
|
beginBatch() {
|
|
|
|
if (this._batching)
|
|
|
|
return;
|
|
|
|
this._batchBlockingDeferred = PromiseUtils.defer();
|
|
|
|
PlacesTransactions.batch(async () => {
|
|
|
|
await this._batchBlockingDeferred.promise;
|
|
|
|
});
|
|
|
|
this._batching = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
endBatch() {
|
|
|
|
if (!this._batching)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._batchBlockingDeferred.resolve();
|
|
|
|
this._batchBlockingDeferred = null;
|
|
|
|
this._batching = false;
|
|
|
|
},
|
|
|
|
};
|
2010-08-09 00:06:47 +04:00
|
|
|
|
2010-08-09 00:06:47 +04:00
|
|
|
var PlacesCommandHook = {
|
2018-02-03 21:49:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a bookmark to the page loaded in the given browser using the
|
|
|
|
* properties dialog.
|
|
|
|
*
|
|
|
|
* @param aBrowser
|
|
|
|
* a <browser> element.
|
2010-08-09 00:06:47 +04:00
|
|
|
* @param [optional] aShowEditUI
|
|
|
|
* whether or not to show the edit-bookmark UI for the bookmark item
|
2018-04-24 20:29:31 +03:00
|
|
|
* @param [optional] aUrl
|
|
|
|
* Option to provide a URL to bookmark rather than the current page
|
|
|
|
* @param [optional] aTitle
|
|
|
|
* Option to provide a title for a bookmark to use rather than the
|
|
|
|
* getting the current page's title
|
2010-08-09 00:06:47 +04:00
|
|
|
*/
|
2018-04-24 20:29:31 +03:00
|
|
|
async bookmarkPage(aBrowser, aShowEditUI, aUrl = null, aTitle = null) {
|
|
|
|
// If aUrl is provided, we want to bookmark that url rather than the
|
|
|
|
// the current page
|
|
|
|
let url = aUrl ? new URL(aUrl) : new URL(aBrowser.currentURI.spec);
|
2018-02-03 21:49:47 +03:00
|
|
|
let info = await PlacesUtils.bookmarks.fetch({ url });
|
|
|
|
let isNewBookmark = !info;
|
|
|
|
if (!info) {
|
2018-04-24 20:29:31 +03:00
|
|
|
let parentGuid = PlacesUtils.bookmarks.unfiledGuid;
|
2018-02-03 21:49:47 +03:00
|
|
|
info = { url, parentGuid };
|
|
|
|
let description = null;
|
|
|
|
let charset = null;
|
|
|
|
|
2018-04-24 20:29:31 +03:00
|
|
|
let docInfo = aUrl ? {} : await this._getPageDetails(aBrowser);
|
2018-02-03 21:49:47 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
if (docInfo.isErrorPage) {
|
|
|
|
let entry = await PlacesUtils.history.fetch(aBrowser.currentURI);
|
|
|
|
if (entry) {
|
|
|
|
info.title = entry.title;
|
|
|
|
}
|
|
|
|
} else {
|
2018-04-24 20:29:31 +03:00
|
|
|
info.title = aTitle || aBrowser.contentTitle;
|
2018-02-03 21:49:47 +03:00
|
|
|
}
|
|
|
|
info.title = info.title || url.href;
|
|
|
|
description = docInfo.description;
|
2018-04-24 20:29:31 +03:00
|
|
|
charset = aUrl ? null : aBrowser.characterSet;
|
2018-02-03 21:49:47 +03:00
|
|
|
} catch (e) {
|
2018-04-24 20:29:31 +03:00
|
|
|
Cu.reportError(e);
|
2018-02-03 21:49:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aShowEditUI && isNewBookmark) {
|
|
|
|
// If we bookmark the page here but open right into a cancelable
|
|
|
|
// state (i.e. new bookmark in Library), start batching here so
|
|
|
|
// all of the actions can be undone in a single undo step.
|
|
|
|
StarUI.beginBatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (description) {
|
|
|
|
info.annotations = [{ name: PlacesUIUtils.DESCRIPTION_ANNO,
|
|
|
|
value: description }];
|
|
|
|
}
|
|
|
|
|
|
|
|
info.guid = await PlacesTransactions.NewBookmark(info).transact();
|
|
|
|
|
|
|
|
// Set the character-set
|
|
|
|
if (charset && !PrivateBrowsingUtils.isBrowserPrivate(aBrowser))
|
|
|
|
PlacesUtils.setCharsetForURI(makeURI(url.href), charset);
|
2010-10-20 16:08:12 +04:00
|
|
|
}
|
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
// If it was not requested to open directly in "edit" mode, we are done.
|
|
|
|
if (!aShowEditUI)
|
|
|
|
return;
|
2010-10-20 16:08:12 +04:00
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
let node = await PlacesUIUtils.promiseNodeLikeFromFetchInfo(info);
|
|
|
|
|
|
|
|
// Dock the panel to the star icon when possible, otherwise dock
|
|
|
|
// it to the content area.
|
|
|
|
if (aBrowser.contentWindow == window.content) {
|
|
|
|
let ubIcons = aBrowser.ownerDocument.getElementById("urlbar-icons");
|
|
|
|
if (ubIcons) {
|
|
|
|
await StarUI.showEditBookmarkPopup(node, ubIcons,
|
|
|
|
"bottomcenter topright",
|
2018-04-24 20:29:31 +03:00
|
|
|
isNewBookmark, url);
|
2018-02-03 21:49:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await StarUI.showEditBookmarkPopup(node, aBrowser, "overlap",
|
2018-04-24 20:29:31 +03:00
|
|
|
isNewBookmark, url);
|
2018-02-03 21:49:47 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_getPageDetails(browser) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
let mm = browser.messageManager;
|
|
|
|
mm.addMessageListener("Bookmarks:GetPageDetails:Result", function listener(msg) {
|
|
|
|
mm.removeMessageListener("Bookmarks:GetPageDetails:Result", listener);
|
|
|
|
resolve(msg.data);
|
|
|
|
});
|
|
|
|
|
2018-04-24 20:29:31 +03:00
|
|
|
mm.sendAsyncMessage("Bookmarks:GetPageDetails", { });
|
2018-02-03 21:49:47 +03:00
|
|
|
});
|
2010-10-20 16:08:12 +04:00
|
|
|
},
|
|
|
|
|
2010-08-09 00:06:47 +04:00
|
|
|
/**
|
|
|
|
* Adds a bookmark to the page targeted by a link.
|
2018-04-24 20:29:31 +03:00
|
|
|
* @param parentId
|
2010-08-09 00:06:47 +04:00
|
|
|
* The folder in which to create a new bookmark if aURL isn't
|
|
|
|
* bookmarked.
|
2018-04-24 20:29:31 +03:00
|
|
|
* @param url (string)
|
2010-08-09 00:06:47 +04:00
|
|
|
* the address of the link target
|
2018-04-24 20:29:31 +03:00
|
|
|
* @param title
|
2010-08-09 00:06:47 +04:00
|
|
|
* The link text
|
2018-04-24 20:29:31 +03:00
|
|
|
* @param [optional] description
|
2018-02-03 21:49:47 +03:00
|
|
|
* The linked page description, if available
|
2010-08-09 00:06:47 +04:00
|
|
|
*/
|
2018-04-24 20:29:31 +03:00
|
|
|
async bookmarkLink(parentId, url, title, description = "") {
|
|
|
|
let bm = await PlacesUtils.bookmarks.fetch({url});
|
|
|
|
if (bm) {
|
|
|
|
let node = await PlacesUIUtils.promiseNodeLikeFromFetchInfo(bm);
|
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "edit", node },
|
|
|
|
window.top);
|
2018-02-03 21:49:47 +03:00
|
|
|
return;
|
2010-08-09 00:06:47 +04:00
|
|
|
}
|
2018-02-03 21:49:47 +03:00
|
|
|
|
2018-04-24 20:29:31 +03:00
|
|
|
let parentGuid = parentId == PlacesUtils.bookmarksMenuFolderId ?
|
|
|
|
PlacesUtils.bookmarks.menuGuid :
|
|
|
|
await PlacesUtils.promiseItemGuid(parentId);
|
2018-07-23 23:11:06 +03:00
|
|
|
let defaultInsertionPoint = new PlacesInsertionPoint({ parentId, parentGuid });
|
2018-04-24 20:29:31 +03:00
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "add",
|
|
|
|
type: "bookmark",
|
2018-04-24 20:29:31 +03:00
|
|
|
uri: makeURI(url),
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
defaultInsertionPoint,
|
2018-02-03 21:49:47 +03:00
|
|
|
hiddenRows: [ "description",
|
|
|
|
"location",
|
|
|
|
"loadInSidebar",
|
|
|
|
"keyword" ]
|
|
|
|
}, window.top);
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-02-03 21:49:47 +03:00
|
|
|
* List of nsIURI objects characterizing the tabs currently open in the
|
|
|
|
* browser. The URIs will be in the order in which their
|
|
|
|
* corresponding tabs appeared and duplicates are discarded.
|
2010-08-09 00:06:47 +04:00
|
|
|
*/
|
2018-02-03 21:49:47 +03:00
|
|
|
get uniqueCurrentPages() {
|
2018-04-24 20:29:31 +03:00
|
|
|
let seenURIs = {};
|
|
|
|
let URIs = [];
|
|
|
|
|
|
|
|
gBrowser.tabs.forEach(tab => {
|
|
|
|
let browser = tab.linkedBrowser;
|
|
|
|
let uri = browser.currentURI;
|
|
|
|
// contentTitle is usually empty.
|
|
|
|
let title = browser.contentTitle || tab.label;
|
|
|
|
let spec = uri.spec;
|
|
|
|
if (!(spec in seenURIs)) {
|
|
|
|
// add to the set of seen URIs
|
|
|
|
seenURIs[uri.spec] = null;
|
|
|
|
URIs.push({ uri, title });
|
|
|
|
}
|
|
|
|
});
|
2010-08-09 00:06:47 +04:00
|
|
|
|
2018-04-24 20:29:31 +03:00
|
|
|
return URIs;
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a folder with bookmarks to all of the currently open tabs in this
|
|
|
|
* window.
|
|
|
|
*/
|
|
|
|
bookmarkCurrentPages: function PCH_bookmarkCurrentPages() {
|
2018-02-03 21:49:47 +03:00
|
|
|
let pages = this.uniqueCurrentPages;
|
|
|
|
if (pages.length > 1) {
|
2018-04-24 20:29:31 +03:00
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "add",
|
|
|
|
type: "folder",
|
|
|
|
URIList: pages,
|
|
|
|
hiddenRows: [ "description" ]
|
|
|
|
}, window);
|
2018-02-03 21:49:47 +03:00
|
|
|
}
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
/**
|
|
|
|
* Updates disabled state for the "Bookmark All Tabs" command.
|
|
|
|
*/
|
|
|
|
updateBookmarkAllTabsCommand:
|
|
|
|
function PCH_updateBookmarkAllTabsCommand() {
|
|
|
|
// There's nothing to do in non-browser windows.
|
|
|
|
if (window.location.href != getBrowserURL())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Disable "Bookmark All Tabs" if there are less than two
|
|
|
|
// "unique current pages".
|
|
|
|
goSetCommandEnabled("Browser:BookmarkAllTabs",
|
|
|
|
this.uniqueCurrentPages.length >= 2);
|
|
|
|
},
|
2010-08-09 00:06:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a Live Bookmark to a feed associated with the current page.
|
|
|
|
* @param url
|
|
|
|
* The nsIURI of the page the feed was attached to
|
|
|
|
* @title title
|
|
|
|
* The title of the feed. Optional.
|
|
|
|
* @subtitle subtitle
|
|
|
|
* A short description of the feed. Optional.
|
|
|
|
*/
|
2018-02-03 21:49:47 +03:00
|
|
|
async addLiveBookmark(url, feedTitle, feedSubtitle) {
|
2018-07-23 23:11:06 +03:00
|
|
|
let toolbarIP = new PlacesInsertionPoint({
|
2018-04-24 20:29:31 +03:00
|
|
|
parentId: PlacesUtils.toolbarFolderId,
|
|
|
|
parentGuid: PlacesUtils.bookmarks.toolbarGuid
|
|
|
|
});
|
2018-02-03 21:49:47 +03:00
|
|
|
|
|
|
|
let feedURI = makeURI(url);
|
|
|
|
let title = feedTitle || gBrowser.contentTitle;
|
|
|
|
let description = feedSubtitle;
|
|
|
|
if (!description) {
|
|
|
|
description = (await this._getPageDetails(gBrowser.selectedBrowser)).description;
|
|
|
|
}
|
2010-08-09 00:06:47 +04:00
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "add",
|
|
|
|
type: "livemark",
|
|
|
|
feedURI,
|
|
|
|
siteURI: gBrowser.currentURI,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
defaultInsertionPoint: toolbarIP,
|
|
|
|
hiddenRows: [ "feedLocation",
|
|
|
|
"siteLocation",
|
|
|
|
"description" ]
|
|
|
|
}, window);
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-02-03 21:49:47 +03:00
|
|
|
* Opens the Places Organizer.
|
2018-04-24 20:29:31 +03:00
|
|
|
* @param {String} item The item to select in the organizer window,
|
|
|
|
* options are (case sensitive):
|
|
|
|
* BookmarksMenu, BookmarksToolbar, UnfiledBookmarks,
|
|
|
|
* AllBookmarks, History.
|
2010-08-09 00:06:47 +04:00
|
|
|
*/
|
2018-04-24 20:29:31 +03:00
|
|
|
showPlacesOrganizer(item) {
|
2018-02-03 21:49:47 +03:00
|
|
|
var organizer = Services.wm.getMostRecentWindow("Places:Organizer");
|
2015-01-19 18:51:12 +03:00
|
|
|
// Due to bug 528706, getMostRecentWindow can return closed windows.
|
2018-02-03 21:49:47 +03:00
|
|
|
if (!organizer || organizer.closed) {
|
2010-08-09 00:06:47 +04:00
|
|
|
// No currently open places window, so open one with the specified mode.
|
2018-02-03 21:49:47 +03:00
|
|
|
openDialog("chrome://communicator/content/places/places.xul",
|
2018-04-24 20:29:31 +03:00
|
|
|
"", "chrome,toolbar=yes,dialog=no,resizable", item);
|
2018-02-03 21:49:47 +03:00
|
|
|
} else {
|
2018-04-24 20:29:31 +03:00
|
|
|
organizer.PlacesOrganizer.selectLeftPaneContainerByHierarchy(item);
|
2018-02-03 21:49:47 +03:00
|
|
|
organizer.focus();
|
2010-08-09 00:06:47 +04:00
|
|
|
}
|
2018-02-03 21:49:47 +03:00
|
|
|
},
|
2010-08-09 00:06:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Functions for handling events in the Bookmarks Toolbar and menu.
|
|
|
|
*/
|
|
|
|
var BookmarksEventHandler = {
|
2018-04-24 20:29:31 +03:00
|
|
|
|
|
|
|
onMouseUp(aEvent) {
|
|
|
|
// Handles left-click with modifier if not browser.bookmarks.openInTabClosesMenu.
|
|
|
|
if (aEvent.button != 0 || PlacesUIUtils.openInTabClosesMenu)
|
|
|
|
return;
|
|
|
|
let target = aEvent.originalTarget;
|
|
|
|
if (target.tagName != "menuitem")
|
|
|
|
return;
|
|
|
|
let modifKey = AppConstants.platform === "macosx" ? aEvent.metaKey
|
|
|
|
: aEvent.ctrlKey;
|
|
|
|
// Don't keep menu open for 'Open all in Tabs'.
|
|
|
|
if (modifKey && !target.classList.contains("openintabs-menuitem")) {
|
|
|
|
target.setAttribute("closemenu", "none");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-01-07 01:21:44 +03:00
|
|
|
/**
|
|
|
|
* Handler for click event for an item in the bookmarks toolbar or menu.
|
|
|
|
* Menus and submenus from the folder buttons bubble up to this handler.
|
|
|
|
* Left-click is handled in the onCommand function.
|
|
|
|
* When items are middle-clicked (or clicked with modifier), open in tabs.
|
|
|
|
* If the click came through a menu, close the menu.
|
|
|
|
* @param aEvent
|
|
|
|
* DOMEvent for the click
|
|
|
|
* @param aView
|
|
|
|
* The places view which aEvent should be associated with.
|
|
|
|
*/
|
|
|
|
onClick: function BEH_onClick(aEvent, aView) {
|
2010-08-09 00:06:47 +04:00
|
|
|
// Only handle middle-click or left-click with modifiers.
|
|
|
|
if (aEvent.button == 2 || (aEvent.button == 0 && !aEvent.shiftKey &&
|
|
|
|
!aEvent.ctrlKey && !aEvent.metaKey))
|
|
|
|
return;
|
|
|
|
|
|
|
|
var target = aEvent.originalTarget;
|
2018-04-24 20:29:31 +03:00
|
|
|
// If this event bubbled up from a menu or menuitem,
|
|
|
|
// close the menus if browser.bookmarks.openInTabClosesMenu.
|
|
|
|
if ((PlacesUIUtils.openInTabClosesMenu && target.tagName == "menuitem") ||
|
|
|
|
target.tagName == "menu" ||
|
|
|
|
target.classList.contains("openintabs-menuitem")) {
|
|
|
|
closeMenus(aEvent.target);
|
|
|
|
}
|
|
|
|
// Command already precesssed so remove any closemenu attr set in onMouseUp.
|
|
|
|
if (aEvent.button == 0 &&
|
|
|
|
target.tagName == "menuitem" &&
|
|
|
|
target.getAttribute("closemenu") == "none") {
|
|
|
|
// On Mac we need to extend when we remove the flag, to avoid any pre-close
|
|
|
|
// animations.
|
|
|
|
setTimeout(() => {
|
|
|
|
target.removeAttribute("closemenu");
|
|
|
|
}, 500);
|
2010-08-09 00:06:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target._placesNode && PlacesUtils.nodeIsContainer(target._placesNode)) {
|
|
|
|
// Don't open the root folder in tabs when the empty area on the toolbar
|
|
|
|
// is middle-clicked or when a non-bookmark item except for Open in Tabs)
|
|
|
|
// in a bookmarks menupopup is middle-clicked.
|
|
|
|
if (target.localName == "menu" || target.localName == "toolbarbutton")
|
2019-01-07 01:21:44 +03:00
|
|
|
PlacesUIUtils.openContainerNodeInTabs(target._placesNode, aEvent, aView);
|
2010-08-09 00:06:47 +04:00
|
|
|
}
|
|
|
|
else if (aEvent.button == 1) {
|
|
|
|
// left-clicks with modifier are already served by onCommand
|
|
|
|
this.onCommand(aEvent);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for command event for an item in the bookmarks toolbar.
|
|
|
|
* Menus and submenus from the folder buttons bubble up to this handler.
|
|
|
|
* Opens the item.
|
|
|
|
* @param aEvent
|
|
|
|
* DOMEvent for the command
|
|
|
|
*/
|
|
|
|
onCommand: function BEH_onCommand(aEvent) {
|
|
|
|
var target = aEvent.originalTarget;
|
|
|
|
if (target._placesNode)
|
|
|
|
PlacesUIUtils.openNodeWithEvent(target._placesNode, aEvent);
|
|
|
|
},
|
|
|
|
|
2011-08-13 14:40:20 +04:00
|
|
|
onPopupShowing: function BEH_onPopupShowing(aEvent) {
|
2011-09-27 23:39:46 +04:00
|
|
|
var browser = getBrowser();
|
2011-08-30 01:58:58 +04:00
|
|
|
if (!aEvent.currentTarget.parentNode._placesView)
|
2011-08-13 14:40:20 +04:00
|
|
|
new PlacesMenu(aEvent, 'place:folder=BOOKMARKS_MENU');
|
|
|
|
|
|
|
|
document.getElementById("Browser:BookmarkAllTabs")
|
2011-09-27 23:39:46 +04:00
|
|
|
.setAttribute("disabled", !browser || browser.tabs.length == 1);
|
2011-08-13 14:40:20 +04:00
|
|
|
},
|
2016-06-21 17:13:24 +03:00
|
|
|
|
2010-08-09 00:06:47 +04:00
|
|
|
fillInBHTooltip: function BEH_fillInBHTooltip(aDocument, aEvent) {
|
|
|
|
var node;
|
|
|
|
var cropped = false;
|
|
|
|
var targetURI;
|
|
|
|
|
|
|
|
if (aDocument.tooltipNode.localName == "treechildren") {
|
|
|
|
var tree = aDocument.tooltipNode.parentNode;
|
|
|
|
var tbo = tree.treeBoxObject;
|
2014-12-23 21:09:05 +03:00
|
|
|
var cell = tbo.getCellAt(aEvent.clientX, aEvent.clientY);
|
|
|
|
if (cell.row == -1)
|
2010-08-09 00:06:47 +04:00
|
|
|
return false;
|
2014-12-23 21:09:05 +03:00
|
|
|
node = tree.view.nodeForTreeIndex(cell.row);
|
|
|
|
cropped = tbo.isCellCropped(cell.row, cell.col);
|
2010-08-09 00:06:47 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Check whether the tooltipNode is a Places node.
|
|
|
|
// In such a case use it, otherwise check for targetURI attribute.
|
|
|
|
var tooltipNode = aDocument.tooltipNode;
|
|
|
|
if (tooltipNode._placesNode)
|
|
|
|
node = tooltipNode._placesNode;
|
|
|
|
else {
|
|
|
|
// This is a static non-Places node.
|
|
|
|
targetURI = tooltipNode.getAttribute("targetURI");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node && !targetURI)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Show node.label as tooltip's title for non-Places nodes.
|
|
|
|
var title = node ? node.title : tooltipNode.label;
|
|
|
|
|
|
|
|
// Show URL only for Places URI-nodes or nodes with a targetURI attribute.
|
|
|
|
var url;
|
|
|
|
if (targetURI || PlacesUtils.nodeIsURI(node))
|
|
|
|
url = targetURI || node.uri;
|
|
|
|
|
|
|
|
// Show tooltip for containers only if their title is cropped.
|
|
|
|
if (!cropped && !url)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
var tooltipTitle = aDocument.getElementById("bhtTitleText");
|
|
|
|
tooltipTitle.hidden = (!title || (title == url));
|
|
|
|
if (!tooltipTitle.hidden)
|
|
|
|
tooltipTitle.textContent = title;
|
|
|
|
|
|
|
|
var tooltipUrl = aDocument.getElementById("bhtUrlText");
|
|
|
|
tooltipUrl.hidden = !url;
|
|
|
|
if (!tooltipUrl.hidden)
|
|
|
|
tooltipUrl.value = url;
|
|
|
|
|
|
|
|
// Show tooltip.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Handles special drag and drop functionality for Places menus that are not
|
|
|
|
// part of a Places view (e.g. the bookmarks menu in the menubar).
|
|
|
|
var PlacesMenuDNDHandler = {
|
|
|
|
_springLoadDelay: 350, // milliseconds
|
|
|
|
_loadTimer: null,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the user enters the <menu> element during a drag.
|
|
|
|
* @param event
|
|
|
|
* The DragEnter event that spawned the opening.
|
|
|
|
*/
|
|
|
|
onDragEnter: function PMDH_onDragEnter(event) {
|
|
|
|
// Opening menus in a Places popup is handled by the view itself.
|
|
|
|
if (!this._isStaticContainer(event.target))
|
|
|
|
return;
|
|
|
|
|
2018-04-24 20:29:31 +03:00
|
|
|
this._loadTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2010-08-09 00:06:47 +04:00
|
|
|
this._loadTimer.initWithCallback(function() {
|
|
|
|
PlacesMenuDNDHandler._loadTimer = null;
|
|
|
|
event.target.lastChild.setAttribute("autoopened", "true");
|
|
|
|
event.target.lastChild.showPopup(event.target.lastChild);
|
2018-02-28 20:33:34 +03:00
|
|
|
}, this._springLoadDelay, Ci.nsITimer.TYPE_ONE_SHOT);
|
2010-08-09 00:06:47 +04:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2010-12-16 01:54:52 +03:00
|
|
|
* Handles dragexit on the <menu> element.
|
2010-08-09 00:06:47 +04:00
|
|
|
* @returns true if the element is a container element (menu or
|
|
|
|
* menu-toolbarbutton), false otherwise.
|
|
|
|
*/
|
2010-12-16 01:54:52 +03:00
|
|
|
onDragExit: function PMDH_onDragExit(event) {
|
2010-08-09 00:06:47 +04:00
|
|
|
// Closing menus in a Places popup is handled by the view itself.
|
|
|
|
if (!this._isStaticContainer(event.target))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (this._loadTimer) {
|
|
|
|
this._loadTimer.cancel();
|
|
|
|
this._loadTimer = null;
|
|
|
|
}
|
2018-04-24 20:29:31 +03:00
|
|
|
let closeTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
2010-08-09 00:06:47 +04:00
|
|
|
closeTimer.initWithCallback(function() {
|
|
|
|
let node = PlacesControllerDragHelper.currentDropTarget;
|
|
|
|
let inHierarchy = false;
|
|
|
|
while (node && !inHierarchy) {
|
|
|
|
inHierarchy = node == event.target;
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
if (!inHierarchy && event.target.lastChild &&
|
|
|
|
event.target.lastChild.hasAttribute("autoopened")) {
|
|
|
|
event.target.lastChild.removeAttribute("autoopened");
|
|
|
|
event.target.lastChild.hidePopup();
|
|
|
|
}
|
2018-02-28 20:33:34 +03:00
|
|
|
}, this._springLoadDelay, Ci.nsITimer.TYPE_ONE_SHOT);
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if a XUL element represents a static container.
|
|
|
|
* @returns true if the element is a container element (menu or
|
|
|
|
* menu-toolbarbutton), false otherwise.
|
|
|
|
*/
|
|
|
|
_isStaticContainer: function PMDH__isContainer(node) {
|
|
|
|
let isMenu = node.localName == "menu" ||
|
|
|
|
(node.localName == "toolbarbutton" &&
|
|
|
|
node.getAttribute("type") == "menu");
|
|
|
|
let isStatic = !("_placesNode" in node) && node.lastChild &&
|
|
|
|
node.lastChild.hasAttribute("placespopup") &&
|
|
|
|
!node.parentNode.hasAttribute("placespopup");
|
|
|
|
return isMenu && isStatic;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the user drags over the <menu> element.
|
|
|
|
* @param event
|
|
|
|
* The DragOver event.
|
|
|
|
*/
|
|
|
|
onDragOver: function PMDH_onDragOver(event) {
|
2018-07-23 23:11:06 +03:00
|
|
|
let ip = new PlacesInsertionPoint({
|
2018-04-24 20:29:31 +03:00
|
|
|
parentId: PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
parentGuid: PlacesUtils.bookmarks.menuGuid
|
|
|
|
});
|
2010-08-09 00:06:47 +04:00
|
|
|
if (ip && PlacesControllerDragHelper.canDrop(ip, event.dataTransfer))
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the user drops on the <menu> element.
|
|
|
|
* @param event
|
|
|
|
* The Drop event.
|
|
|
|
*/
|
|
|
|
onDrop: function PMDH_onDrop(event) {
|
|
|
|
// Put the item at the end of bookmark menu.
|
2018-07-23 23:11:06 +03:00
|
|
|
let ip = new PlacesInsertionPoint({
|
2018-04-24 20:29:31 +03:00
|
|
|
parentId: PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
parentGuid: PlacesUtils.bookmarks.menuGuid
|
|
|
|
});
|
2010-08-09 00:06:47 +04:00
|
|
|
PlacesControllerDragHelper.onDrop(ip, event.dataTransfer);
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-02-03 21:49:47 +03:00
|
|
|
var BookmarkingUI = {
|
2011-01-18 20:57:34 +03:00
|
|
|
_hasBookmarksObserver: false,
|
2018-02-03 21:49:47 +03:00
|
|
|
_itemGuids: new Set(),
|
2010-09-06 17:31:20 +04:00
|
|
|
|
2017-05-22 17:53:31 +03:00
|
|
|
uninit: function BUI_uninit()
|
2011-01-18 20:57:34 +03:00
|
|
|
{
|
|
|
|
if (this._hasBookmarksObserver) {
|
2010-09-06 17:31:20 +04:00
|
|
|
PlacesUtils.bookmarks.removeObserver(this);
|
2011-01-18 20:57:34 +03:00
|
|
|
}
|
2011-03-13 21:45:54 +03:00
|
|
|
|
2017-05-22 17:53:31 +03:00
|
|
|
if (this._pendingUpdate) {
|
|
|
|
delete this._pendingUpdate;
|
2011-03-13 21:45:54 +03:00
|
|
|
}
|
2010-09-06 17:31:20 +04:00
|
|
|
},
|
|
|
|
|
2011-01-18 20:57:34 +03:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
2018-02-28 20:33:34 +03:00
|
|
|
Ci.nsINavBookmarkObserver
|
2011-01-18 20:57:34 +03:00
|
|
|
]),
|
|
|
|
|
|
|
|
get _starredTooltip()
|
|
|
|
{
|
|
|
|
delete this._starredTooltip;
|
|
|
|
return this._starredTooltip =
|
|
|
|
gNavigatorBundle.getString("starButtonOn.tooltip");
|
|
|
|
},
|
2017-05-22 17:53:31 +03:00
|
|
|
|
2011-01-18 20:57:34 +03:00
|
|
|
get _unstarredTooltip()
|
|
|
|
{
|
|
|
|
delete this._unstarredTooltip;
|
|
|
|
return this._unstarredTooltip =
|
|
|
|
gNavigatorBundle.getString("starButtonOff.tooltip");
|
|
|
|
},
|
|
|
|
|
2017-05-22 17:53:31 +03:00
|
|
|
updateStarState: function BUI_updateStarState() {
|
2011-01-18 20:57:34 +03:00
|
|
|
this._uri = gBrowser.currentURI;
|
2017-05-22 17:53:31 +03:00
|
|
|
this._itemGuids = [];
|
|
|
|
let aItemGuids = [];
|
|
|
|
|
|
|
|
// those objects are use to check if we are in the current iteration before
|
|
|
|
// returning any result.
|
|
|
|
let pendingUpdate = this._pendingUpdate = {};
|
|
|
|
|
|
|
|
PlacesUtils.bookmarks.fetch({url: this._uri}, b => aItemGuids.push(b.guid))
|
2018-04-24 20:29:31 +03:00
|
|
|
.catch(Cu.reportError)
|
2017-05-22 17:53:31 +03:00
|
|
|
.then(() => {
|
|
|
|
if (pendingUpdate != this._pendingUpdate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's possible that onItemAdded gets called before the async statement
|
|
|
|
// calls back. For such an edge case, retain all unique entries from the
|
|
|
|
// array.
|
|
|
|
this._itemGuids = this._itemGuids.filter(
|
|
|
|
guid => !aItemGuids.includes(guid)
|
|
|
|
).concat(aItemGuids);
|
|
|
|
|
|
|
|
this._updateStar();
|
|
|
|
|
|
|
|
// Start observing bookmarks if needed.
|
|
|
|
if (!this._hasBookmarksObserver) {
|
|
|
|
try {
|
2017-08-04 16:26:12 +03:00
|
|
|
PlacesUtils.bookmarks.addObserver(this);
|
2017-05-22 17:53:31 +03:00
|
|
|
this._hasBookmarksObserver = true;
|
|
|
|
} catch (ex) {
|
2018-04-24 20:29:31 +03:00
|
|
|
Cu.reportError("BookmarkingUI failed adding a bookmarks observer: " + ex);
|
2017-05-22 17:53:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete this._pendingUpdate;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateStar: function BUI__updateStar()
|
2011-01-18 20:57:34 +03:00
|
|
|
{
|
|
|
|
let starIcon = document.getElementById("star-button");
|
2017-05-22 17:53:31 +03:00
|
|
|
if (this._itemGuids.length > 0) {
|
2010-09-06 17:31:20 +04:00
|
|
|
starIcon.setAttribute("starred", "true");
|
2011-01-18 20:57:34 +03:00
|
|
|
starIcon.setAttribute("tooltiptext", this._starredTooltip);
|
2010-09-06 17:31:20 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
starIcon.removeAttribute("starred");
|
2011-01-18 20:57:34 +03:00
|
|
|
starIcon.setAttribute("tooltiptext", this._unstarredTooltip);
|
2010-09-06 17:31:20 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-05-22 17:53:31 +03:00
|
|
|
onClick: function BUI_onClick(aEvent)
|
2011-01-18 20:57:34 +03:00
|
|
|
{
|
2011-03-13 21:45:54 +03:00
|
|
|
// Ignore clicks on the star while we update its state.
|
2017-05-22 17:53:31 +03:00
|
|
|
if (aEvent.button == 0 && !this._pendingUpdate)
|
2018-04-24 20:29:31 +03:00
|
|
|
PlacesCommandHook.bookmarkPage(gBrowser.selectedBrowser,
|
|
|
|
this._itemGuids.length > 0);
|
|
|
|
|
2010-09-06 17:31:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// nsINavBookmarkObserver
|
2017-05-22 17:53:31 +03:00
|
|
|
onItemAdded(aItemId, aParentId, aIndex, aItemType, aURI, aTitle, aDateAdded, aGuid) {
|
2011-02-28 21:28:10 +03:00
|
|
|
if (aURI && aURI.equals(this._uri)) {
|
2011-01-18 20:57:34 +03:00
|
|
|
// If a new bookmark has been added to the tracked uri, register it.
|
2017-05-22 17:53:31 +03:00
|
|
|
if (!this._itemGuids.includes(aGuid)) {
|
|
|
|
this._itemGuids.push(aGuid);
|
|
|
|
// Only need to update the UI if it wasn't marked as starred before:
|
|
|
|
if (this._itemGuids.length == 1) {
|
|
|
|
this._updateStar();
|
|
|
|
}
|
2011-01-18 20:57:34 +03:00
|
|
|
}
|
|
|
|
}
|
2010-09-06 17:31:20 +04:00
|
|
|
},
|
|
|
|
|
2017-05-22 17:53:31 +03:00
|
|
|
onItemRemoved(aItemId, aParentId, aIndex, aItemType, aURI, aGuid) {
|
|
|
|
let index = this._itemGuids.indexOf(aGuid);
|
2011-01-18 20:57:34 +03:00
|
|
|
// If one of the tracked bookmarks has been removed, unregister it.
|
|
|
|
if (index != -1) {
|
2017-05-22 17:53:31 +03:00
|
|
|
this._itemGuids.splice(index, 1);
|
|
|
|
// Only need to update the UI if the page is no longer starred
|
|
|
|
if (this._itemGuids.length == 0) {
|
|
|
|
this._updateStar();
|
|
|
|
}
|
2011-01-18 20:57:34 +03:00
|
|
|
}
|
2010-09-06 17:31:20 +04:00
|
|
|
},
|
|
|
|
|
2017-05-22 17:53:31 +03:00
|
|
|
onItemChanged(aItemId, aProperty, aIsAnnotationProperty, aNewValue, aLastModified,
|
|
|
|
aItemType, aParentId, aGuid) {
|
2011-01-18 20:57:34 +03:00
|
|
|
if (aProperty == "uri") {
|
2017-05-22 17:53:31 +03:00
|
|
|
let index = this._itemGuids.indexOf(aGuid);
|
2011-01-18 20:57:34 +03:00
|
|
|
// If the changed bookmark was tracked, check if it is now pointing to
|
|
|
|
// a different uri and unregister it.
|
|
|
|
if (index != -1 && aNewValue != this._uri.spec) {
|
2017-05-22 17:53:31 +03:00
|
|
|
this._itemGuids.splice(index, 1);
|
|
|
|
// Only need to update the UI if the page is no longer starred
|
|
|
|
if (this._itemGuids.length == 0) {
|
|
|
|
this._updateStar();
|
|
|
|
}
|
|
|
|
} else if (index == -1 && aNewValue == this._uri.spec) {
|
|
|
|
// If another bookmark is now pointing to the tracked uri, register it.
|
|
|
|
this._itemGuids.push(aGuid);
|
|
|
|
// Only need to update the UI if it wasn't marked as starred before:
|
|
|
|
if (this._itemGuids.length == 1) {
|
|
|
|
this._updateStar();
|
|
|
|
}
|
2011-01-18 20:57:34 +03:00
|
|
|
}
|
|
|
|
}
|
2010-09-06 17:31:20 +04:00
|
|
|
},
|
|
|
|
|
2011-01-18 20:57:34 +03:00
|
|
|
onBeginUpdateBatch: function () {},
|
|
|
|
onEndUpdateBatch: function () {},
|
|
|
|
onItemVisited: function () {},
|
|
|
|
onItemMoved: function () {}
|
2010-09-06 17:31:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-08-09 00:06:47 +04:00
|
|
|
// This object handles the initialization and uninitialization of the bookmarks
|
2017-05-22 17:53:31 +03:00
|
|
|
// toolbar. updateStarState is called when the browser window is opened and
|
2010-08-09 00:06:47 +04:00
|
|
|
// after closing the toolbar customization dialog.
|
2015-10-08 06:53:00 +03:00
|
|
|
var PlacesToolbarHelper = {
|
2010-08-09 00:06:47 +04:00
|
|
|
_place: "place:folder=TOOLBAR",
|
|
|
|
get _viewElt() {
|
|
|
|
return document.getElementById("PlacesToolbar");
|
|
|
|
},
|
|
|
|
|
|
|
|
init: function PTH_init() {
|
2012-06-18 01:04:27 +04:00
|
|
|
let viewElt = this._viewElt;
|
|
|
|
if (!viewElt || viewElt._placesView)
|
|
|
|
return;
|
|
|
|
|
2013-03-17 07:34:49 +04:00
|
|
|
// There is no need to initialize the toolbar if customizing because
|
2012-06-18 01:04:27 +04:00
|
|
|
// init() will be called when the customization is done.
|
2013-03-17 07:34:49 +04:00
|
|
|
if (this._isCustomizing)
|
2012-06-18 01:04:27 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
new PlacesToolbar(this._place);
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
customizeStart: function PTH_customizeStart() {
|
|
|
|
let viewElt = this._viewElt;
|
|
|
|
if (viewElt && viewElt._placesView)
|
|
|
|
viewElt._placesView.uninit();
|
2012-06-18 01:04:27 +04:00
|
|
|
|
|
|
|
this._isCustomizing = true;
|
2010-08-09 00:06:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
customizeDone: function PTH_customizeDone() {
|
2012-06-18 01:04:27 +04:00
|
|
|
this._isCustomizing = false;
|
2010-08-09 00:06:47 +04:00
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-14 18:57:59 +04:00
|
|
|
// Handles the bookmarks menu popup
|
2015-10-08 06:53:00 +03:00
|
|
|
var BookmarksMenu = {
|
2012-01-14 18:57:59 +04:00
|
|
|
_popupInitialized: {},
|
|
|
|
onPopupShowing: function BM_onPopupShowing(aEvent, aPrefix) {
|
|
|
|
if (!(aPrefix in this._popupInitialized)) {
|
2010-08-09 00:06:47 +04:00
|
|
|
// First popupshowing event, initialize immutable attributes.
|
2012-01-14 18:57:59 +04:00
|
|
|
this._popupInitialized[aPrefix] = true;
|
2010-08-09 00:06:47 +04:00
|
|
|
|
|
|
|
// Need to set the label on Unsorted Bookmarks menu.
|
|
|
|
let unsortedBookmarksElt =
|
2012-01-14 18:57:59 +04:00
|
|
|
document.getElementById(aPrefix + "unsortedBookmarksFolderMenu");
|
2010-08-09 00:06:47 +04:00
|
|
|
unsortedBookmarksElt.label =
|
2016-04-12 17:26:30 +03:00
|
|
|
PlacesUtils.getString("OtherBookmarksFolderTitle");
|
2010-08-09 00:06:47 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|