2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Places Command Controller.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Google Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Goodger <beng@google.com>
|
|
|
|
* Myk Melez <myk@mozilla.org>
|
|
|
|
* Asaf Romano <mano@mozilla.com>
|
2007-07-15 02:44:50 -07:00
|
|
|
* Sungjoon Steve Won <stevewon@gmail.com>
|
2008-03-13 12:25:49 -07:00
|
|
|
* Dietrich Ayala <dietrich@mozilla.com>
|
2008-09-19 08:47:45 -07:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
function LOG(str) {
|
|
|
|
dump("*** " + str + "\n");
|
|
|
|
}
|
|
|
|
|
2007-06-11 22:24:58 -07:00
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Cr = Components.results;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
__defineGetter__("PlacesUtils", function() {
|
|
|
|
delete this.PlacesUtils
|
|
|
|
var tmpScope = {};
|
|
|
|
Components.utils.import("resource://gre/modules/utils.js", tmpScope);
|
|
|
|
return this.PlacesUtils = tmpScope.PlacesUtils;
|
|
|
|
});
|
2007-08-22 07:47:56 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
const LOAD_IN_SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
|
|
|
|
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
2008-11-05 10:15:49 -08:00
|
|
|
const GUID_ANNO = "placesInternal/GUID";
|
2008-03-04 13:23:04 -08:00
|
|
|
const LMANNO_FEEDURI = "livemark/feedURI";
|
|
|
|
const LMANNO_SITEURI = "livemark/siteURI";
|
2008-03-04 14:12:27 -08:00
|
|
|
const ORGANIZER_FOLDER_ANNO = "PlacesOrganizer/OrganizerFolder";
|
|
|
|
const ORGANIZER_QUERY_ANNO = "PlacesOrganizer/OrganizerQuery";
|
2008-04-25 14:36:40 -07:00
|
|
|
const ORGANIZER_LEFTPANE_VERSION = 4;
|
2008-03-04 13:23:04 -08:00
|
|
|
|
2007-08-10 08:50:15 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// On Mac OSX, the transferable system converts "\r\n" to "\n\n", where we
|
|
|
|
// really just want "\n".
|
|
|
|
const NEWLINE= "\n";
|
|
|
|
#else
|
|
|
|
// On other platforms, the transferable system converts "\r\n" to "\n".
|
|
|
|
const NEWLINE = "\r\n";
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
function QI_node(aNode, aIID) {
|
2008-03-13 18:58:01 -07:00
|
|
|
return aNode.QueryInterface(aIID);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
function asVisit(aNode) { return QI_node(aNode, Ci.nsINavHistoryVisitResultNode); }
|
|
|
|
function asFullVisit(aNode){ return QI_node(aNode, Ci.nsINavHistoryFullVisitResultNode);}
|
|
|
|
function asContainer(aNode){ return QI_node(aNode, Ci.nsINavHistoryContainerResultNode);}
|
|
|
|
function asQuery(aNode) { return QI_node(aNode, Ci.nsINavHistoryQueryResultNode); }
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
var PlacesUIUtils = {
|
2007-05-31 17:39:09 -07:00
|
|
|
/**
|
|
|
|
* The Microsummary Service
|
|
|
|
*/
|
|
|
|
get microsummaries() {
|
2007-10-20 13:40:16 -07:00
|
|
|
delete this.microsummaries;
|
|
|
|
return this.microsummaries = Cc["@mozilla.org/microsummary/service;1"].
|
|
|
|
getService(Ci.nsIMicrosummaryService);
|
2007-05-31 17:39:09 -07:00
|
|
|
},
|
|
|
|
|
2007-05-16 18:14:27 -07:00
|
|
|
get RDF() {
|
2007-10-20 13:40:16 -07:00
|
|
|
delete this.RDF;
|
|
|
|
return this.RDF = Cc["@mozilla.org/rdf/rdf-service;1"].
|
|
|
|
getService(Ci.nsIRDFService);
|
2007-05-16 18:14:27 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get localStore() {
|
2007-10-20 13:40:16 -07:00
|
|
|
delete this.localStore;
|
|
|
|
return this.localStore = this.RDF.GetDataSource("rdf:local-store");
|
2007-05-16 18:14:27 -07:00
|
|
|
},
|
|
|
|
|
2007-07-15 02:44:50 -07:00
|
|
|
get ptm() {
|
2007-10-20 13:40:16 -07:00
|
|
|
delete this.ptm;
|
|
|
|
return this.ptm = Cc["@mozilla.org/browser/placesTransactionsService;1"].
|
|
|
|
getService(Ci.nsIPlacesTransactionsService);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-09-19 01:13:20 -07:00
|
|
|
get clipboard() {
|
2007-10-20 13:40:16 -07:00
|
|
|
delete this.clipboard;
|
|
|
|
return this.clipboard = Cc["@mozilla.org/widget/clipboard;1"].
|
|
|
|
getService(Ci.nsIClipboard);
|
2007-09-19 01:13:20 -07:00
|
|
|
},
|
|
|
|
|
2007-11-12 21:24:55 -08:00
|
|
|
get URIFixup() {
|
|
|
|
delete this.URIFixup;
|
|
|
|
return this.URIFixup = Cc["@mozilla.org/docshell/urifixup;1"].
|
|
|
|
getService(Ci.nsIURIFixup);
|
|
|
|
},
|
|
|
|
|
2008-03-11 01:15:32 -07:00
|
|
|
get ellipsis() {
|
|
|
|
delete this.ellipsis;
|
|
|
|
var pref = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
return this.ellipsis = pref.getComplexValue("intl.ellipsis",
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
|
|
|
},
|
|
|
|
|
2007-11-12 21:24:55 -08:00
|
|
|
/**
|
|
|
|
* Makes a URI from a spec, and do fixup
|
|
|
|
* @param aSpec
|
|
|
|
* The string spec of the URI
|
|
|
|
* @returns A URI object for the spec.
|
|
|
|
*/
|
|
|
|
createFixedURI: function PU_createFixedURI(aSpec) {
|
|
|
|
return this.URIFixup.createFixupURI(aSpec, 0);
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Wraps a string in a nsISupportsString wrapper
|
|
|
|
* @param aString
|
|
|
|
* The string to wrap
|
|
|
|
* @returns A nsISupportsString object containing a string.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
_wrapString: function PU__wrapString(aString) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var s = Cc["@mozilla.org/supports-string;1"].
|
|
|
|
createInstance(Ci.nsISupportsString);
|
|
|
|
s.data = aString;
|
|
|
|
return s;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String bundle helpers
|
|
|
|
*/
|
|
|
|
get _bundle() {
|
2007-10-24 19:02:28 -07:00
|
|
|
const PLACES_STRING_BUNDLE_URI =
|
2007-10-16 17:14:46 -07:00
|
|
|
"chrome://browser/locale/places/places.properties";
|
2007-10-24 19:02:28 -07:00
|
|
|
delete this._bundle;
|
|
|
|
return this._bundle = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle(PLACES_STRING_BUNDLE_URI);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
getFormattedString: function PU_getFormattedString(key, params) {
|
|
|
|
return this._bundle.formatStringFromName(key, params, params.length);
|
|
|
|
},
|
2007-03-26 17:52:59 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
getString: function PU_getString(key) {
|
|
|
|
return this._bundle.GetStringFromName(key);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a transaction for copying a uri item from one container to another
|
|
|
|
* as a bookmark.
|
2008-03-26 18:58:52 -07:00
|
|
|
* @param aData
|
|
|
|
* JSON object of dropped or pasted item properties
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aContainer
|
|
|
|
* The container being copied into
|
|
|
|
* @param aIndex
|
|
|
|
* The index within the container the item is copied to
|
|
|
|
* @returns A nsITransaction object that performs the copy.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
_getURIItemCopyTransaction: function (aData, aContainer, aIndex) {
|
2008-03-13 12:25:49 -07:00
|
|
|
return this.ptm.createItem(PlacesUtils._uri(aData.uri), aContainer, aIndex,
|
2007-07-15 02:44:50 -07:00
|
|
|
aData.title, "");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a transaction for copying a bookmark item from one container to
|
|
|
|
* another.
|
2008-03-26 18:58:52 -07:00
|
|
|
* @param aData
|
|
|
|
* JSON object of dropped or pasted item properties
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aContainer
|
|
|
|
* The container being copied into
|
|
|
|
* @param aIndex
|
|
|
|
* The index within the container the item is copied to
|
2007-04-09 17:36:43 -07:00
|
|
|
* @param [optional] aExcludeAnnotations
|
|
|
|
* Optional, array of annotations (listed by their names) to exclude
|
|
|
|
* when copying the item.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @returns A nsITransaction object that performs the copy.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
_getBookmarkItemCopyTransaction:
|
|
|
|
function PU__getBookmarkItemCopyTransaction(aData, aContainer, aIndex,
|
|
|
|
aExcludeAnnotations) {
|
2008-03-13 12:25:49 -07:00
|
|
|
var itemURL = PlacesUtils._uri(aData.uri);
|
2007-07-13 17:25:26 -07:00
|
|
|
var itemTitle = aData.title;
|
2008-03-13 12:25:49 -07:00
|
|
|
var keyword = aData.keyword || null;
|
|
|
|
var annos = aData.annos || [];
|
2008-11-05 10:15:49 -08:00
|
|
|
// always exclude GUID when copying any item
|
|
|
|
var excludeAnnos = [GUID_ANNO];
|
|
|
|
if (aExcludeAnnotations)
|
|
|
|
excludeAnnos = excludeAnnos.concat(aExcludeAnnotations);
|
|
|
|
annos = annos.filter(function(aValue, aIndex, aArray) {
|
|
|
|
return excludeAnnos.indexOf(aValue.name) == -1;
|
|
|
|
});
|
2007-12-28 13:48:37 -08:00
|
|
|
var childTxns = [];
|
|
|
|
if (aData.dateAdded)
|
|
|
|
childTxns.push(this.ptm.editItemDateAdded(null, aData.dateAdded));
|
|
|
|
if (aData.lastModified)
|
|
|
|
childTxns.push(this.ptm.editItemLastModified(null, aData.lastModified));
|
2008-03-26 18:58:52 -07:00
|
|
|
if (aData.tags) {
|
|
|
|
var tags = aData.tags.split(", ");
|
|
|
|
// filter out tags already present, so that undo doesn't remove them
|
|
|
|
// from pre-existing bookmarks
|
|
|
|
var storedTags = PlacesUtils.tagging.getTagsForURI(itemURL, {});
|
|
|
|
tags = tags.filter(function (aTag) {
|
|
|
|
return (storedTags.indexOf(aTag) == -1);
|
|
|
|
}, this);
|
|
|
|
if (tags.length)
|
|
|
|
childTxns.push(this.ptm.tagURI(itemURL, tags));
|
|
|
|
}
|
2007-09-19 01:13:20 -07:00
|
|
|
|
2007-07-15 02:44:50 -07:00
|
|
|
return this.ptm.createItem(itemURL, aContainer, aIndex, itemTitle, keyword,
|
2007-12-28 13:48:37 -08:00
|
|
|
annos, childTxns);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a transaction for copying (recursively nesting to include children)
|
2007-09-19 01:13:20 -07:00
|
|
|
* a folder (or container) and its contents from one folder to another.
|
2007-07-13 17:25:26 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aData
|
2007-07-13 17:25:26 -07:00
|
|
|
* Unwrapped dropped folder data - Obj containing folder and children
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aContainer
|
|
|
|
* The container we are copying into
|
|
|
|
* @param aIndex
|
|
|
|
* The index in the destination container to insert the new items
|
|
|
|
* @returns A nsITransaction object that will perform the copy.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
_getFolderCopyTransaction:
|
|
|
|
function PU__getFolderCopyTransaction(aData, aContainer, aIndex) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var self = this;
|
2007-07-13 17:25:26 -07:00
|
|
|
function getChildItemsTransactions(aChildren) {
|
2007-03-30 13:36:32 -07:00
|
|
|
var childItemsTransactions = [];
|
2007-07-13 17:25:26 -07:00
|
|
|
var cc = aChildren.length;
|
|
|
|
var index = aIndex;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (var i = 0; i < cc; ++i) {
|
2007-03-30 13:36:32 -07:00
|
|
|
var txn = null;
|
2007-07-13 17:25:26 -07:00
|
|
|
var node = aChildren[i];
|
2007-09-19 01:13:20 -07:00
|
|
|
|
2008-04-22 09:53:17 -07:00
|
|
|
// Make sure that items are given the correct index, this will be
|
|
|
|
// passed by the transaction manager to the backend for the insertion.
|
|
|
|
// Insertion behaves differently if index == DEFAULT_INDEX (append)
|
|
|
|
if (aIndex != PlacesUtils.bookmarks.DEFAULT_INDEX)
|
|
|
|
index = i;
|
2007-09-19 01:13:20 -07:00
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
if (node.type == PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER) {
|
|
|
|
if (node.livemark && node.annos) // node is a livemark
|
|
|
|
txn = self._getLivemarkCopyTransaction(node, aContainer, index);
|
2008-04-02 13:38:35 -07:00
|
|
|
else
|
|
|
|
txn = self._getFolderCopyTransaction(node, aContainer, index);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-03-13 12:25:49 -07:00
|
|
|
else if (node.type == PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR)
|
2007-07-18 14:39:23 -07:00
|
|
|
txn = self.ptm.createSeparator(-1, index);
|
2008-03-13 12:25:49 -07:00
|
|
|
else if (node.type == PlacesUtils.TYPE_X_MOZ_PLACE)
|
2007-07-13 17:25:26 -07:00
|
|
|
txn = self._getBookmarkItemCopyTransaction(node, -1, index);
|
2007-03-30 13:36:32 -07:00
|
|
|
|
|
|
|
NS_ASSERT(txn, "Unexpected item under a bookmarks folder");
|
|
|
|
if (txn)
|
|
|
|
childItemsTransactions.push(txn);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-30 13:36:32 -07:00
|
|
|
return childItemsTransactions;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-15 02:44:50 -07:00
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
// tag folders use tag transactions
|
|
|
|
if (aContainer == PlacesUtils.bookmarks.tagsFolder) {
|
|
|
|
var txns = [];
|
|
|
|
if (aData.children) {
|
|
|
|
aData.children.forEach(function(aChild) {
|
|
|
|
txns.push(this.ptm.tagURI(PlacesUtils._uri(aChild.uri), [aData.title]));
|
|
|
|
}, this);
|
|
|
|
}
|
|
|
|
return this.ptm.aggregateTransactions("addTags", txns);
|
|
|
|
}
|
|
|
|
else if (aData.livemark && aData.annos) {
|
|
|
|
// Place is a Livemark Container
|
|
|
|
return this._getLivemarkCopyTransaction(aData, aContainer, aIndex);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var childItems = getChildItemsTransactions(aData.children);
|
|
|
|
if (aData.dateAdded)
|
|
|
|
childItems.push(this.ptm.editItemDateAdded(null, aData.dateAdded));
|
|
|
|
if (aData.lastModified)
|
|
|
|
childItems.push(this.ptm.editItemLastModified(null, aData.lastModified));
|
|
|
|
|
|
|
|
var annos = aData.annos || [];
|
2008-11-05 10:15:49 -08:00
|
|
|
annos = annos.filter(function(aAnno) {
|
|
|
|
// always exclude GUID when copying any item
|
|
|
|
return aAnno.name != GUID_ANNO;
|
|
|
|
});
|
2008-03-13 12:25:49 -07:00
|
|
|
return this.ptm.createFolder(aData.title, aContainer, aIndex, annos, childItems);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
_getLivemarkCopyTransaction:
|
|
|
|
function PU__getLivemarkCopyTransaction(aData, aContainer, aIndex) {
|
|
|
|
NS_ASSERT(aData.livemark && aData.annos, "node is not a livemark");
|
|
|
|
// Place is a Livemark Container
|
|
|
|
var feedURI = null;
|
|
|
|
var siteURI = null;
|
|
|
|
aData.annos = aData.annos.filter(function(aAnno) {
|
|
|
|
if (aAnno.name == LMANNO_FEEDURI) {
|
2008-03-18 09:44:22 -07:00
|
|
|
feedURI = PlacesUtils._uri(aAnno.value);
|
2008-03-13 12:25:49 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (aAnno.name == LMANNO_SITEURI) {
|
2008-03-18 09:44:22 -07:00
|
|
|
siteURI = PlacesUtils._uri(aAnno.value);
|
2008-03-13 12:25:49 -07:00
|
|
|
return false;
|
|
|
|
}
|
2008-11-05 10:15:49 -08:00
|
|
|
// always exclude GUID when copying any item
|
|
|
|
return aAnno.name != GUID_ANNO;
|
|
|
|
});
|
2008-03-13 12:25:49 -07:00
|
|
|
return this.ptm.createLivemark(feedURI, siteURI, aData.title, aContainer,
|
|
|
|
aIndex, aData.annos);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a Transaction for the drop or paste of a blob of data into
|
|
|
|
* a container.
|
|
|
|
* @param data
|
|
|
|
* The unwrapped data blob of dropped or pasted data.
|
|
|
|
* @param type
|
|
|
|
* The content type of the data
|
|
|
|
* @param container
|
|
|
|
* The container the data was dropped or pasted into
|
|
|
|
* @param index
|
|
|
|
* The index within the container the item was dropped or pasted at
|
|
|
|
* @param copy
|
|
|
|
* The drag action was copy, so don't move folders or links.
|
|
|
|
* @returns An object implementing nsITransaction that can perform
|
|
|
|
* the move/insert.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
makeTransaction: function PU_makeTransaction(data, type, container,
|
|
|
|
index, copy) {
|
2007-07-13 17:25:26 -07:00
|
|
|
switch (data.type) {
|
2008-03-13 12:25:49 -07:00
|
|
|
case PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER:
|
2007-03-22 10:30:00 -07:00
|
|
|
if (copy)
|
|
|
|
return this._getFolderCopyTransaction(data, container, index);
|
2008-03-13 12:25:49 -07:00
|
|
|
else { // Move the item
|
|
|
|
var id = data.folder ? data.folder.id : data.id;
|
|
|
|
return this.ptm.moveItem(id, container, index);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PlacesUtils.TYPE_X_MOZ_PLACE:
|
|
|
|
if (data.id <= 0) // non-bookmark item
|
|
|
|
return this._getURIItemCopyTransaction(data, container, index);
|
|
|
|
|
|
|
|
if (copy) {
|
|
|
|
// Copying a child of a live-bookmark by itself should result
|
|
|
|
// as a new normal bookmark item (bug 376731)
|
2008-11-05 10:15:49 -08:00
|
|
|
return this._getBookmarkItemCopyTransaction(data, container, index,
|
|
|
|
["livemark/bookmarkFeedURI"]);
|
2008-03-13 12:25:49 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return this.ptm.moveItem(data.id, container, index);
|
|
|
|
break;
|
|
|
|
case PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR:
|
2007-03-22 10:30:00 -07:00
|
|
|
// There is no data in a separator, so copying it just amounts to
|
|
|
|
// inserting a new separator.
|
2008-04-03 09:23:45 -07:00
|
|
|
if (copy)
|
|
|
|
return this.ptm.createSeparator(container, index);
|
|
|
|
// Move the separator otherwise
|
|
|
|
return this.ptm.moveItem(data.id, container, index);
|
2008-03-13 12:25:49 -07:00
|
|
|
break;
|
|
|
|
default:
|
2008-09-19 08:47:45 -07:00
|
|
|
if (type == PlacesUtils.TYPE_X_MOZ_URL ||
|
|
|
|
type == PlacesUtils.TYPE_UNICODE) {
|
|
|
|
var title = (type == PlacesUtils.TYPE_X_MOZ_URL) ? data.title :
|
|
|
|
data.uri;
|
|
|
|
return this.ptm.createItem(PlacesUtils._uri(data.uri),
|
|
|
|
container, index, title);
|
2008-03-13 12:25:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-03-13 12:25:49 -07:00
|
|
|
return null;
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-03-26 17:52:59 -07:00
|
|
|
/**
|
|
|
|
* Methods to show the bookmarkProperties dialog in its various modes.
|
|
|
|
*
|
2007-03-28 13:32:51 -07:00
|
|
|
* The showMinimalAdd* methods open the dialog by its alternative URI. Thus
|
2007-03-26 17:52:59 -07:00
|
|
|
* they persist the dialog dimensions separately from the showAdd* methods.
|
2007-03-30 16:47:07 -07:00
|
|
|
* Note these variants also do not return the dialog "performed" state since
|
|
|
|
* they may not open the dialog modally.
|
2007-03-26 17:52:59 -07:00
|
|
|
*/
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Shows the "Add Bookmark" dialog.
|
|
|
|
*
|
|
|
|
* @param [optional] aURI
|
|
|
|
* An nsIURI object for which the "add bookmark" dialog is
|
|
|
|
* to be shown.
|
|
|
|
* @param [optional] aTitle
|
|
|
|
* The default title for the new bookmark.
|
|
|
|
* @param [optional] aDescription
|
|
|
|
The default description for the new bookmark
|
|
|
|
* @param [optional] aDefaultInsertionPoint
|
|
|
|
* The default insertion point for the new item. If set, the folder
|
|
|
|
* picker would be hidden unless aShowPicker is set to true, in which
|
|
|
|
* case the dialog only uses the folder identifier from the insertion
|
|
|
|
* point as the initially selected item in the folder picker.
|
|
|
|
* @param [optional] aShowPicker
|
|
|
|
* see above
|
|
|
|
* @param [optional] aLoadInSidebar
|
|
|
|
* If true, the dialog will default to load the new item in the
|
|
|
|
* sidebar (as a web panel).
|
2007-03-28 13:32:51 -07:00
|
|
|
* @param [optional] aKeyword
|
|
|
|
* The default keyword for the new bookmark. The keyword field
|
|
|
|
* will be shown in the dialog if this is used.
|
2007-05-14 20:59:38 -07:00
|
|
|
* @param [optional] aPostData
|
|
|
|
* POST data for POST-style keywords.
|
2008-04-08 11:41:04 -07:00
|
|
|
* @param [optional] aCharSet
|
|
|
|
* The character set for the bookmarked page.
|
2007-03-22 10:30:00 -07:00
|
|
|
* @return true if any transaction has been performed.
|
|
|
|
*
|
|
|
|
* Notes:
|
2008-04-28 02:41:18 -07:00
|
|
|
* - the location, description and "loadInSidebar" fields are
|
2007-03-22 10:30:00 -07:00
|
|
|
* visible only if there is no initial URI (aURI is null).
|
|
|
|
* - When aDefaultInsertionPoint is not set, the dialog defaults to the
|
|
|
|
* bookmarks root folder.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
showAddBookmarkUI: function PU_showAddBookmarkUI(aURI,
|
|
|
|
aTitle,
|
|
|
|
aDescription,
|
|
|
|
aDefaultInsertionPoint,
|
|
|
|
aShowPicker,
|
|
|
|
aLoadInSidebar,
|
|
|
|
aKeyword,
|
2008-04-08 11:41:04 -07:00
|
|
|
aPostData,
|
|
|
|
aCharSet) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var info = {
|
|
|
|
action: "add",
|
2007-03-26 17:52:59 -07:00
|
|
|
type: "bookmark"
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-03-26 17:52:59 -07:00
|
|
|
if (aURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
info.uri = aURI;
|
2007-03-26 17:52:59 -07:00
|
|
|
|
|
|
|
// allow default empty title
|
|
|
|
if (typeof(aTitle) == "string")
|
|
|
|
info.title = aTitle;
|
|
|
|
|
|
|
|
if (aDescription)
|
|
|
|
info.description = aDescription;
|
|
|
|
|
|
|
|
if (aDefaultInsertionPoint) {
|
|
|
|
info.defaultInsertionPoint = aDefaultInsertionPoint;
|
|
|
|
if (!aShowPicker)
|
2008-10-30 10:21:47 -07:00
|
|
|
info.hiddenRows = ["folderPicker"];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-03-26 17:52:59 -07:00
|
|
|
if (aLoadInSidebar)
|
|
|
|
info.loadBookmarkInSidebar = true;
|
|
|
|
|
2007-05-14 20:59:38 -07:00
|
|
|
if (typeof(aKeyword) == "string") {
|
2007-03-28 13:32:51 -07:00
|
|
|
info.keyword = aKeyword;
|
2007-05-14 20:59:38 -07:00
|
|
|
if (typeof(aPostData) == "string")
|
|
|
|
info.postData = aPostData;
|
2008-04-08 11:41:04 -07:00
|
|
|
if (typeof(aCharSet) == "string")
|
|
|
|
info.charSet = aCharSet;
|
2007-05-14 20:59:38 -07:00
|
|
|
}
|
2007-03-28 13:32:51 -07:00
|
|
|
|
2007-03-26 17:52:59 -07:00
|
|
|
return this._showBookmarkDialog(info);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see showAddBookmarkUI
|
|
|
|
* This opens the dialog with only the name and folder pickers visible by
|
|
|
|
* default.
|
|
|
|
*
|
|
|
|
* You can still pass in the various paramaters as the default properties
|
|
|
|
* for the new bookmark.
|
2007-03-28 13:32:51 -07:00
|
|
|
*
|
|
|
|
* The keyword field will be visible only if the aKeyword parameter
|
|
|
|
* was used.
|
2007-03-26 17:52:59 -07:00
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
showMinimalAddBookmarkUI:
|
|
|
|
function PU_showMinimalAddBookmarkUI(aURI, aTitle, aDescription,
|
|
|
|
aDefaultInsertionPoint, aShowPicker,
|
2008-04-08 11:41:04 -07:00
|
|
|
aLoadInSidebar, aKeyword, aPostData,
|
|
|
|
aCharSet) {
|
2007-03-26 17:52:59 -07:00
|
|
|
var info = {
|
|
|
|
action: "add",
|
|
|
|
type: "bookmark",
|
2008-10-30 10:21:47 -07:00
|
|
|
hiddenRows: ["description"]
|
2007-03-26 17:52:59 -07:00
|
|
|
};
|
|
|
|
if (aURI)
|
|
|
|
info.uri = aURI;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// allow default empty title
|
|
|
|
if (typeof(aTitle) == "string")
|
|
|
|
info.title = aTitle;
|
|
|
|
|
|
|
|
if (aDescription)
|
|
|
|
info.description = aDescription;
|
|
|
|
|
|
|
|
if (aDefaultInsertionPoint) {
|
|
|
|
info.defaultInsertionPoint = aDefaultInsertionPoint;
|
|
|
|
if (!aShowPicker)
|
2008-10-30 10:21:47 -07:00
|
|
|
info.hiddenRows.push("folderPicker");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aLoadInSidebar)
|
|
|
|
info.loadBookmarkInSidebar = true;
|
2008-10-30 10:21:47 -07:00
|
|
|
else
|
|
|
|
info.hiddenRows = info.hiddenRows.concat(["location", "loadInSidebar"]);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-14 20:59:38 -07:00
|
|
|
if (typeof(aKeyword) == "string") {
|
2007-03-28 13:32:51 -07:00
|
|
|
info.keyword = aKeyword;
|
2008-10-30 10:21:47 -07:00
|
|
|
// hide the Tags field if we are adding a keyword
|
|
|
|
info.hiddenRows.push("tags");
|
2007-05-14 20:59:38 -07:00
|
|
|
if (typeof(aPostData) == "string")
|
|
|
|
info.postData = aPostData;
|
2008-04-08 11:41:04 -07:00
|
|
|
if (typeof(aCharSet) == "string")
|
|
|
|
info.charSet = aCharSet;
|
2007-05-14 20:59:38 -07:00
|
|
|
}
|
2007-03-28 13:32:51 -07:00
|
|
|
else
|
|
|
|
info.hiddenRows.push("keyword");
|
|
|
|
|
2007-03-30 16:47:07 -07:00
|
|
|
this._showBookmarkDialog(info, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the "Add Live Bookmark" dialog.
|
|
|
|
*
|
|
|
|
* @param [optional] aFeedURI
|
|
|
|
* The feed URI for which the dialog is to be shown (nsIURI).
|
|
|
|
* @param [optional] aSiteURI
|
|
|
|
* The site URI for the new live-bookmark (nsIURI).
|
|
|
|
* @param [optional] aDefaultInsertionPoint
|
|
|
|
* The default insertion point for the new item. If set, the folder
|
|
|
|
* picker would be hidden unless aShowPicker is set to true, in which
|
|
|
|
* case the dialog only uses the folder identifier from the insertion
|
|
|
|
* point as the initially selected item in the folder picker.
|
|
|
|
* @param [optional] aShowPicker
|
|
|
|
* see above
|
|
|
|
* @return true if any transaction has been performed.
|
2007-03-26 17:52:59 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* Notes:
|
|
|
|
* - the feedURI and description fields are visible only if there is no
|
|
|
|
* initial feed URI (aFeedURI is null).
|
|
|
|
* - When aDefaultInsertionPoint is not set, the dialog defaults to the
|
|
|
|
* bookmarks root folder.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
showAddLivemarkUI: function PU_showAddLivemarkURI(aFeedURI,
|
|
|
|
aSiteURI,
|
|
|
|
aTitle,
|
|
|
|
aDescription,
|
|
|
|
aDefaultInsertionPoint,
|
|
|
|
aShowPicker) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var info = {
|
|
|
|
action: "add",
|
2007-03-26 17:52:59 -07:00
|
|
|
type: "livemark"
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2007-03-26 17:52:59 -07:00
|
|
|
if (aFeedURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
info.feedURI = aFeedURI;
|
2007-03-26 17:52:59 -07:00
|
|
|
if (aSiteURI)
|
|
|
|
info.siteURI = aSiteURI;
|
|
|
|
|
|
|
|
// allow default empty title
|
|
|
|
if (typeof(aTitle) == "string")
|
|
|
|
info.title = aTitle;
|
|
|
|
|
|
|
|
if (aDescription)
|
|
|
|
info.description = aDescription;
|
|
|
|
|
|
|
|
if (aDefaultInsertionPoint) {
|
|
|
|
info.defaultInsertionPoint = aDefaultInsertionPoint;
|
|
|
|
if (!aShowPicker)
|
2008-10-30 10:21:47 -07:00
|
|
|
info.hiddenRows = ["folderPicker"];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-26 17:52:59 -07:00
|
|
|
return this._showBookmarkDialog(info);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see showAddLivemarkUI
|
|
|
|
* This opens the dialog with only the name and folder pickers visible by
|
|
|
|
* default.
|
|
|
|
*
|
|
|
|
* You can still pass in the various paramaters as the default properties
|
|
|
|
* for the new live-bookmark.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
showMinimalAddLivemarkUI:
|
|
|
|
function PU_showMinimalAddLivemarkURI(aFeedURI, aSiteURI, aTitle,
|
|
|
|
aDescription, aDefaultInsertionPoint,
|
|
|
|
aShowPicker) {
|
2007-03-26 17:52:59 -07:00
|
|
|
var info = {
|
|
|
|
action: "add",
|
|
|
|
type: "livemark",
|
2008-10-30 10:21:47 -07:00
|
|
|
hiddenRows: ["feedLocation", "siteLocation", "description"]
|
2007-03-26 17:52:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (aFeedURI)
|
|
|
|
info.feedURI = aFeedURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aSiteURI)
|
|
|
|
info.siteURI = aSiteURI;
|
|
|
|
|
|
|
|
// allow default empty title
|
|
|
|
if (typeof(aTitle) == "string")
|
|
|
|
info.title = aTitle;
|
|
|
|
|
|
|
|
if (aDescription)
|
|
|
|
info.description = aDescription;
|
|
|
|
|
|
|
|
if (aDefaultInsertionPoint) {
|
|
|
|
info.defaultInsertionPoint = aDefaultInsertionPoint;
|
|
|
|
if (!aShowPicker)
|
2008-10-30 10:21:47 -07:00
|
|
|
info.hiddenRows.push("folderPicker");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-03-30 16:47:07 -07:00
|
|
|
this._showBookmarkDialog(info, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an "Add Bookmarks" dialog to allow the adding of a folder full
|
|
|
|
* of bookmarks corresponding to the objects in the uriList. This will
|
|
|
|
* be called most often as the result of a "Bookmark All Tabs..." command.
|
|
|
|
*
|
|
|
|
* @param aURIList List of nsIURI objects representing the locations
|
|
|
|
* to be bookmarked.
|
|
|
|
* @return true if any transaction has been performed.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
showMinimalAddMultiBookmarkUI: function PU_showAddMultiBookmarkUI(aURIList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERT(aURIList.length,
|
|
|
|
"showAddMultiBookmarkUI expects a list of nsIURI objects");
|
|
|
|
var info = {
|
|
|
|
action: "add",
|
2007-03-30 13:36:32 -07:00
|
|
|
type: "folder",
|
2007-03-22 10:30:00 -07:00
|
|
|
hiddenRows: ["description"],
|
|
|
|
URIList: aURIList
|
|
|
|
};
|
2007-03-30 16:47:07 -07:00
|
|
|
this._showBookmarkDialog(info, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2008-04-28 02:41:18 -07:00
|
|
|
* Opens the properties dialog for a given item identifier.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
2008-04-28 02:41:18 -07:00
|
|
|
* @param aItemId
|
|
|
|
* item identifier for which the properties are to be shown
|
|
|
|
* @param aType
|
|
|
|
* item type, either "bookmark" or "folder"
|
2007-03-22 10:30:00 -07:00
|
|
|
* @return true if any transaction has been performed.
|
|
|
|
*/
|
2008-04-28 02:41:18 -07:00
|
|
|
showItemProperties: function PU_showItemProperties(aItemId, aType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var info = {
|
|
|
|
action: "edit",
|
2008-04-28 02:41:18 -07:00
|
|
|
type: aType,
|
|
|
|
itemId: aItemId
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
return this._showBookmarkDialog(info);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the "New Folder" dialog.
|
|
|
|
*
|
|
|
|
* @param [optional] aTitle
|
|
|
|
* The default title for the new bookmark.
|
|
|
|
* @param [optional] aDefaultInsertionPoint
|
|
|
|
* The default insertion point for the new item. If set, the folder
|
|
|
|
* picker would be hidden unless aShowPicker is set to true, in which
|
|
|
|
* case the dialog only uses the folder identifier from the insertion
|
|
|
|
* point as the initially selected item in the folder picker.
|
|
|
|
* @param [optional] aShowPicker
|
|
|
|
* see above
|
|
|
|
* @return true if any transaction has been performed.
|
2007-03-26 17:52:59 -07:00
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
showAddFolderUI:
|
|
|
|
function PU_showAddFolderUI(aTitle, aDefaultInsertionPoint, aShowPicker) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var info = {
|
|
|
|
action: "add",
|
|
|
|
type: "folder",
|
|
|
|
hiddenRows: []
|
|
|
|
};
|
|
|
|
|
|
|
|
// allow default empty title
|
|
|
|
if (typeof(aTitle) == "string")
|
|
|
|
info.title = aTitle;
|
|
|
|
|
|
|
|
if (aDefaultInsertionPoint) {
|
|
|
|
info.defaultInsertionPoint = aDefaultInsertionPoint;
|
|
|
|
if (!aShowPicker)
|
2008-10-30 10:21:47 -07:00
|
|
|
info.hiddenRows.push("folderPicker");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return this._showBookmarkDialog(info);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the bookmark dialog corresponding to the specified info
|
|
|
|
*
|
|
|
|
* @param aInfo
|
|
|
|
* Describes the item to be edited/added in the dialog.
|
|
|
|
* See documentation at the top of bookmarkProperties.js
|
2007-03-26 17:52:59 -07:00
|
|
|
* @param aMinimalUI
|
|
|
|
* [optional] if true, the dialog is opened by its alternative
|
|
|
|
* chrome: uri.
|
2007-03-30 16:47:07 -07:00
|
|
|
*
|
|
|
|
* @return true if any transaction has been performed, false otherwise.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
_showBookmarkDialog: function PU__showBookmarkDialog(aInfo, aMinimalUI) {
|
2007-03-26 17:52:59 -07:00
|
|
|
var dialogURL = aMinimalUI ?
|
2007-05-31 12:13:15 -07:00
|
|
|
"chrome://browser/content/places/bookmarkProperties2.xul" :
|
2007-03-26 17:52:59 -07:00
|
|
|
"chrome://browser/content/places/bookmarkProperties.xul";
|
|
|
|
|
2007-03-30 16:47:07 -07:00
|
|
|
var features;
|
|
|
|
if (aMinimalUI)
|
|
|
|
features = "centerscreen,chrome,dialog,resizable,modal";
|
|
|
|
else
|
|
|
|
features = "centerscreen,chrome,modal,resizable=no";
|
|
|
|
window.openDialog(dialogURL, "", features, aInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
return ("performed" in aInfo && aInfo.performed);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the closet ancestor places view for the given DOM node
|
|
|
|
* @param aNode
|
|
|
|
* a DOM node
|
|
|
|
* @return the closet ancestor places view if exists, null otherwsie.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
getViewForNode: function PU_getViewForNode(aNode) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var node = aNode;
|
2008-04-02 13:05:57 -07:00
|
|
|
|
|
|
|
// the view for a <menu> of which its associated menupopup is a places view,
|
|
|
|
// is the menupopup
|
|
|
|
if (node.localName == "menu" && !node.node &&
|
|
|
|
node.firstChild.getAttribute("type") == "places")
|
|
|
|
return node.firstChild;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
while (node) {
|
|
|
|
// XXXmano: Use QueryInterface(nsIPlacesView) once we implement it...
|
|
|
|
if (node.getAttribute("type") == "places")
|
|
|
|
return node;
|
|
|
|
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2007-12-27 17:53:59 -08:00
|
|
|
/**
|
|
|
|
* By calling this before we visit a URL, we will use TRANSITION_TYPED
|
|
|
|
* as the transition for the visit to that URL (if we don't have a referrer).
|
|
|
|
* This is used when visiting pages from the history menu, history sidebar,
|
|
|
|
* url bar, url autocomplete results, and history searches from the places
|
|
|
|
* organizer. If we don't call this, we'll treat those visits as
|
|
|
|
* TRANSITION_LINK.
|
|
|
|
*/
|
|
|
|
markPageAsTyped: function PU_markPageAsTyped(aURL) {
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory)
|
|
|
|
.markPageAsTyped(this.createFixedURI(aURL));
|
2007-12-27 17:53:59 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* By calling this before we visit a URL, we will use TRANSITION_BOOKMARK
|
|
|
|
* as the transition for the visit to that URL (if we don't have a referrer).
|
|
|
|
* This is used when visiting pages from the bookmarks menu,
|
|
|
|
* personal toolbar, and bookmarks from within the places organizer.
|
|
|
|
* If we don't call this, we'll treat those visits as TRANSITION_LINK.
|
|
|
|
*/
|
|
|
|
markPageAsFollowedBookmark: function PU_markPageAsFollowedBookmark(aURL) {
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUtils.history.markPageAsFollowedBookmark(this.createFixedURI(aURL));
|
2007-12-27 17:53:59 -08:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Allows opening of javascript/data URI only if the given node is
|
|
|
|
* bookmarked (see bug 224521).
|
|
|
|
* @param aURINode
|
|
|
|
* a URI node
|
|
|
|
* @return true if it's safe to open the node in the browser, false otherwise.
|
2007-03-26 17:52:59 -07:00
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
checkURLSecurity: function PU_checkURLSecurity(aURINode) {
|
2008-03-13 12:25:49 -07:00
|
|
|
if (!PlacesUtils.nodeIsBookmark(aURINode)) {
|
|
|
|
var uri = PlacesUtils._uri(aURINode.uri);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (uri.schemeIs("javascript") || uri.schemeIs("data")) {
|
|
|
|
const BRANDING_BUNDLE_URI = "chrome://branding/locale/brand.properties";
|
|
|
|
var brandShortName = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle(BRANDING_BUNDLE_URI).
|
|
|
|
GetStringFromName("brandShortName");
|
|
|
|
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
|
|
|
|
|
|
|
var errorStr = this.getString("load-js-data-url-error");
|
2007-05-22 13:19:45 -07:00
|
|
|
promptService.alert(window, brandShortName, errorStr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2007-03-26 17:52:59 -07:00
|
|
|
* Get the description associated with a document, as specified in a <META>
|
2007-03-22 10:30:00 -07:00
|
|
|
* element.
|
|
|
|
* @param doc
|
|
|
|
* A DOM Document to get a description for
|
2007-03-26 17:52:59 -07:00
|
|
|
* @returns A description string if a META element was discovered with a
|
2007-03-22 10:30:00 -07:00
|
|
|
* "description" or "httpequiv" attribute, empty string otherwise.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
getDescriptionFromDocument: function PU_getDescriptionFromDocument(doc) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var metaElements = doc.getElementsByTagName("META");
|
|
|
|
for (var i = 0; i < metaElements.length; ++i) {
|
2007-07-03 08:39:33 -07:00
|
|
|
if (metaElements[i].name.toLowerCase() == "description" ||
|
2007-03-22 10:30:00 -07:00
|
|
|
metaElements[i].httpEquiv.toLowerCase() == "description") {
|
|
|
|
return metaElements[i].content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
2007-03-25 14:56:52 -07:00
|
|
|
},
|
|
|
|
|
2007-08-15 18:15:50 -07:00
|
|
|
/**
|
|
|
|
* Retrieve the description of an item
|
|
|
|
* @param aItemId
|
|
|
|
* item identifier
|
|
|
|
* @returns the description of the given item, or an empty string if it is
|
|
|
|
* not set.
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
getItemDescription: function PU_getItemDescription(aItemId) {
|
2008-03-13 12:25:49 -07:00
|
|
|
if (PlacesUtils.annotations.itemHasAnnotation(aItemId, DESCRIPTION_ANNO))
|
|
|
|
return PlacesUtils.annotations.getItemAnnotation(aItemId, DESCRIPTION_ANNO);
|
2007-08-15 18:15:50 -07:00
|
|
|
return "";
|
|
|
|
},
|
|
|
|
|
2007-09-02 12:03:24 -07:00
|
|
|
/**
|
|
|
|
* Gives the user a chance to cancel loading lots of tabs at once
|
|
|
|
*/
|
2007-10-16 17:14:46 -07:00
|
|
|
_confirmOpenInTabs: function PU__confirmOpenInTabs(numTabsToOpen) {
|
2007-09-02 12:03:24 -07:00
|
|
|
var pref = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
|
|
|
|
const kWarnOnOpenPref = "browser.tabs.warnOnOpen";
|
|
|
|
var reallyOpen = true;
|
|
|
|
if (pref.getBoolPref(kWarnOnOpenPref)) {
|
|
|
|
if (numTabsToOpen >= pref.getIntPref("browser.tabs.maxOpenBeforeWarn")) {
|
|
|
|
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
|
|
|
|
|
|
|
// default to true: if it were false, we wouldn't get this far
|
|
|
|
var warnOnOpen = { value: true };
|
|
|
|
|
|
|
|
var messageKey = "tabs.openWarningMultipleBranded";
|
|
|
|
var openKey = "tabs.openButtonMultiple";
|
|
|
|
const BRANDING_BUNDLE_URI = "chrome://branding/locale/brand.properties";
|
|
|
|
var brandShortName = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService).
|
|
|
|
createBundle(BRANDING_BUNDLE_URI).
|
|
|
|
GetStringFromName("brandShortName");
|
|
|
|
|
|
|
|
var buttonPressed = promptService.confirmEx(window,
|
|
|
|
this.getString("tabs.openWarningTitle"),
|
|
|
|
this.getFormattedString(messageKey, [numTabsToOpen, brandShortName]),
|
|
|
|
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0)
|
|
|
|
+ (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
|
|
|
|
this.getString(openKey), null, null,
|
|
|
|
this.getFormattedString("tabs.openWarningPromptMeBranded",
|
|
|
|
[brandShortName]), warnOnOpen);
|
|
|
|
|
|
|
|
reallyOpen = (buttonPressed == 0);
|
|
|
|
// don't set the pref unless they press OK and it's false
|
|
|
|
if (reallyOpen && !warnOnOpen.value)
|
|
|
|
pref.setBoolPref(kWarnOnOpenPref, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reallyOpen;
|
|
|
|
},
|
|
|
|
|
2007-12-27 17:53:59 -08:00
|
|
|
/** aItemsToOpen needs to be an array of objects of the form:
|
|
|
|
* {uri: string, isBookmark: boolean}
|
|
|
|
*/
|
|
|
|
_openTabset: function PU__openTabset(aItemsToOpen, aEvent) {
|
|
|
|
var urls = [];
|
2008-01-25 00:23:10 -08:00
|
|
|
for (var i = 0; i < aItemsToOpen.length; i++) {
|
|
|
|
var item = aItemsToOpen[i];
|
2007-12-27 17:53:59 -08:00
|
|
|
if (item.isBookmark)
|
|
|
|
this.markPageAsFollowedBookmark(item.uri);
|
|
|
|
else
|
|
|
|
this.markPageAsTyped(item.uri);
|
|
|
|
|
|
|
|
urls.push(item.uri);
|
|
|
|
}
|
|
|
|
|
2007-09-02 12:03:24 -07:00
|
|
|
var browserWindow = getTopWin();
|
|
|
|
var where = browserWindow ?
|
|
|
|
whereToOpenLink(aEvent, false, true) : "window";
|
|
|
|
if (where == "window") {
|
|
|
|
window.openDialog(getBrowserURL(), "_blank",
|
2007-12-27 17:53:59 -08:00
|
|
|
"chrome,all,dialog=no", urls.join("|"));
|
2007-09-02 12:03:24 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var loadInBackground = where == "tabshifted" ? true : false;
|
|
|
|
var replaceCurrentTab = where == "tab" ? false : true;
|
2007-12-27 17:53:59 -08:00
|
|
|
browserWindow.getBrowser().loadTabs(urls, loadInBackground,
|
2007-09-02 12:03:24 -07:00
|
|
|
replaceCurrentTab);
|
|
|
|
},
|
|
|
|
|
2007-10-16 17:14:46 -07:00
|
|
|
openContainerNodeInTabs: function PU_openContainerInTabs(aNode, aEvent) {
|
2008-03-13 12:25:49 -07:00
|
|
|
var urlsToOpen = PlacesUtils.getURLsForContainerNode(aNode);
|
2007-09-02 12:03:24 -07:00
|
|
|
if (!this._confirmOpenInTabs(urlsToOpen.length))
|
|
|
|
return;
|
2007-12-27 17:53:59 -08:00
|
|
|
|
2007-09-02 12:03:24 -07:00
|
|
|
this._openTabset(urlsToOpen, aEvent);
|
|
|
|
},
|
|
|
|
|
2007-10-16 17:14:46 -07:00
|
|
|
openURINodesInTabs: function PU_openURINodesInTabs(aNodes, aEvent) {
|
2007-09-02 12:03:24 -07:00
|
|
|
var urlsToOpen = [];
|
|
|
|
for (var i=0; i < aNodes.length; i++) {
|
2007-12-27 17:53:59 -08:00
|
|
|
// skip over separators and folders
|
2008-03-13 12:25:49 -07:00
|
|
|
if (PlacesUtils.nodeIsURI(aNodes[i]))
|
|
|
|
urlsToOpen.push({uri: aNodes[i].uri, isBookmark: PlacesUtils.nodeIsBookmark(aNodes[i])});
|
2007-09-02 12:03:24 -07:00
|
|
|
}
|
|
|
|
this._openTabset(urlsToOpen, aEvent);
|
2007-09-19 01:13:20 -07:00
|
|
|
},
|
|
|
|
|
2008-02-26 02:37:59 -08:00
|
|
|
/**
|
|
|
|
* Loads the node's URL in the appropriate tab or window or as a web
|
|
|
|
* panel given the user's preference specified by modifier keys tracked by a
|
|
|
|
* DOM mouse/key event.
|
|
|
|
* @param aNode
|
|
|
|
* An uri result node.
|
|
|
|
* @param aEvent
|
|
|
|
* The DOM mouse/key event with modifier keys set that track the
|
|
|
|
* user's preferred destination window or tab.
|
|
|
|
*/
|
|
|
|
openNodeWithEvent: function PU_openNodeWithEvent(aNode, aEvent) {
|
|
|
|
this.openNodeIn(aNode, whereToOpenLink(aEvent));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the node's URL in the appropriate tab or window or as a
|
|
|
|
* web panel.
|
|
|
|
* see also openUILinkIn
|
|
|
|
*/
|
|
|
|
openNodeIn: function PU_openNodeIn(aNode, aWhere) {
|
|
|
|
if (aNode && PlacesUtils.nodeIsURI(aNode) &&
|
2008-03-13 12:25:49 -07:00
|
|
|
this.checkURLSecurity(aNode)) {
|
2008-02-26 02:37:59 -08:00
|
|
|
var isBookmark = PlacesUtils.nodeIsBookmark(aNode);
|
|
|
|
|
|
|
|
if (isBookmark)
|
2008-03-13 12:25:49 -07:00
|
|
|
this.markPageAsFollowedBookmark(aNode.uri);
|
2008-02-26 02:37:59 -08:00
|
|
|
else
|
2008-03-13 12:25:49 -07:00
|
|
|
this.markPageAsTyped(aNode.uri);
|
2008-02-26 02:37:59 -08:00
|
|
|
|
|
|
|
// Check whether the node is a bookmark which should be opened as
|
|
|
|
// a web panel
|
|
|
|
if (aWhere == "current" && isBookmark) {
|
|
|
|
if (PlacesUtils.annotations
|
|
|
|
.itemHasAnnotation(aNode.itemId, LOAD_IN_SIDEBAR_ANNO)) {
|
|
|
|
var w = getTopWin();
|
|
|
|
if (w) {
|
|
|
|
w.openWebPanel(aNode.title, aNode.uri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
openUILinkIn(aNode.uri, aWhere);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
/**
|
|
|
|
* Helper for the toolbar and menu views
|
|
|
|
*/
|
2008-03-13 12:25:49 -07:00
|
|
|
createMenuItemForNode:
|
|
|
|
function PUU_createMenuItemForNode(aNode, aContainersMap) {
|
2007-10-24 19:02:28 -07:00
|
|
|
var element;
|
|
|
|
var type = aNode.type;
|
|
|
|
if (type == Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR)
|
|
|
|
element = document.createElement("menuseparator");
|
|
|
|
else {
|
|
|
|
var iconURI = aNode.icon;
|
|
|
|
var iconURISpec = "";
|
|
|
|
if (iconURI)
|
|
|
|
iconURISpec = iconURI.spec;
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
if (PlacesUtils.uriTypes.indexOf(type) != -1) {
|
2007-10-24 19:02:28 -07:00
|
|
|
element = document.createElement("menuitem");
|
|
|
|
element.className = "menuitem-iconic bookmark-item";
|
|
|
|
}
|
2008-03-13 12:25:49 -07:00
|
|
|
else if (PlacesUtils.containerTypes.indexOf(type) != -1) {
|
2007-10-24 19:02:28 -07:00
|
|
|
element = document.createElement("menu");
|
|
|
|
element.setAttribute("container", "true");
|
2007-11-19 18:01:53 -08:00
|
|
|
|
2008-04-15 10:09:00 -07:00
|
|
|
if (aNode.type == Ci.nsINavHistoryResultNode.RESULT_TYPE_QUERY) {
|
2007-11-19 18:01:53 -08:00
|
|
|
element.setAttribute("query", "true");
|
2008-04-15 10:09:00 -07:00
|
|
|
if (PlacesUtils.nodeIsTagQuery(aNode))
|
|
|
|
element.setAttribute("tagContainer", "true");
|
|
|
|
else if (PlacesUtils.nodeIsDay(aNode))
|
|
|
|
element.setAttribute("dayContainer", "true");
|
|
|
|
else if (PlacesUtils.nodeIsHost(aNode))
|
|
|
|
element.setAttribute("hostContainer", "true");
|
|
|
|
}
|
2008-02-20 18:17:52 -08:00
|
|
|
else if (aNode.itemId != -1) {
|
2008-03-13 12:25:49 -07:00
|
|
|
if (PlacesUtils.nodeIsLivemarkContainer(aNode))
|
2008-02-06 13:19:59 -08:00
|
|
|
element.setAttribute("livemark", "true");
|
2007-11-19 18:01:53 -08:00
|
|
|
}
|
2007-10-24 19:02:28 -07:00
|
|
|
|
|
|
|
var popup = document.createElement("menupopup");
|
2008-02-20 18:17:52 -08:00
|
|
|
popup.setAttribute("placespopup", "true");
|
2007-10-24 19:02:28 -07:00
|
|
|
popup._resultNode = asContainer(aNode);
|
2008-10-17 16:53:08 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// Binding on Mac native menus is lazy attached, so onPopupShowing,
|
|
|
|
// in the capturing phase, fields are not yet initialized.
|
|
|
|
// In that phase we have to ensure markers are not undefined to build
|
|
|
|
// the popup correctly.
|
|
|
|
popup._startMarker = -1;
|
|
|
|
popup._endMarker = -1;
|
|
|
|
#else
|
2007-10-24 19:02:28 -07:00
|
|
|
// no context menu on mac
|
|
|
|
popup.setAttribute("context", "placesContext");
|
|
|
|
#endif
|
|
|
|
element.appendChild(popup);
|
|
|
|
if (aContainersMap)
|
|
|
|
aContainersMap.push({ resultNode: aNode, domNode: popup });
|
|
|
|
element.className = "menu-iconic bookmark-item";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw "Unexpected node";
|
|
|
|
|
2008-03-11 01:15:32 -07:00
|
|
|
element.setAttribute("label", this.getBestTitle(aNode));
|
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
if (iconURISpec)
|
|
|
|
element.setAttribute("image", iconURISpec);
|
|
|
|
}
|
|
|
|
element.node = aNode;
|
|
|
|
element.node.viewIndex = 0;
|
|
|
|
|
|
|
|
return element;
|
2007-11-19 18:01:53 -08:00
|
|
|
},
|
|
|
|
|
2008-03-12 04:08:08 -07:00
|
|
|
cleanPlacesPopup: function PU_cleanPlacesPopup(aPopup) {
|
2008-09-19 08:47:45 -07:00
|
|
|
// Remove places popup children and update markers to keep track of
|
|
|
|
// their indices.
|
|
|
|
var start = aPopup._startMarker != -1 ? aPopup._startMarker + 1 : 0;
|
|
|
|
var end = aPopup._endMarker != -1 ? aPopup._endMarker :
|
|
|
|
aPopup.childNodes.length;
|
2008-03-12 04:08:08 -07:00
|
|
|
var items = [];
|
2008-09-19 08:47:45 -07:00
|
|
|
var placesNodeFound = false;
|
|
|
|
for (var i = start; i < end; ++i) {
|
2008-03-12 04:08:08 -07:00
|
|
|
var item = aPopup.childNodes[i];
|
|
|
|
if (item.getAttribute("builder") == "end") {
|
2008-09-19 08:47:45 -07:00
|
|
|
// we need to do this for menus that have static content at the end but
|
|
|
|
// are initially empty, eg. the history menu, we need to know where to
|
|
|
|
// start inserting new items.
|
2008-03-12 04:08:08 -07:00
|
|
|
aPopup._endMarker = i;
|
2008-09-19 08:47:45 -07:00
|
|
|
break;
|
2008-03-12 04:08:08 -07:00
|
|
|
}
|
2008-09-19 08:47:45 -07:00
|
|
|
if (item.node) {
|
2008-03-12 04:08:08 -07:00
|
|
|
items.push(item);
|
2008-09-19 08:47:45 -07:00
|
|
|
placesNodeFound = true;
|
2008-03-12 04:08:08 -07:00
|
|
|
}
|
2008-09-19 08:47:45 -07:00
|
|
|
else {
|
|
|
|
// This is static content...
|
|
|
|
if (!placesNodeFound)
|
|
|
|
// ...at the start of the popup
|
|
|
|
// Initialized in menu.xml, in the base binding
|
|
|
|
aPopup._startMarker++;
|
|
|
|
else {
|
|
|
|
// ...after places nodes
|
|
|
|
aPopup._endMarker = i;
|
|
|
|
break;
|
2008-03-12 04:08:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-09-19 08:47:45 -07:00
|
|
|
|
|
|
|
for (var i = 0; i < items.length; ++i) {
|
|
|
|
aPopup.removeChild(items[i]);
|
|
|
|
if (aPopup._endMarker != -1)
|
|
|
|
aPopup._endMarker--;
|
|
|
|
}
|
2008-03-12 04:08:08 -07:00
|
|
|
},
|
|
|
|
|
2008-03-11 01:15:32 -07:00
|
|
|
getBestTitle: function PU_getBestTitle(aNode) {
|
|
|
|
var title;
|
2008-03-13 12:25:49 -07:00
|
|
|
if (!aNode.title && PlacesUtils.uriTypes.indexOf(aNode.type) != -1) {
|
2008-03-11 01:15:32 -07:00
|
|
|
// if node title is empty, try to set the label using host and filename
|
2008-03-18 09:44:22 -07:00
|
|
|
// PlacesUtils._uri() will throw if aNode.uri is not a valid URI
|
2008-03-11 01:15:32 -07:00
|
|
|
try {
|
2008-03-13 12:25:49 -07:00
|
|
|
var uri = PlacesUtils._uri(aNode.uri);
|
2008-03-11 01:15:32 -07:00
|
|
|
var host = uri.host;
|
|
|
|
var fileName = uri.QueryInterface(Ci.nsIURL).fileName;
|
|
|
|
// if fileName is empty, use path to distinguish labels
|
|
|
|
title = host + (fileName ?
|
|
|
|
(host ? "/" + this.ellipsis + "/" : "") + fileName :
|
|
|
|
uri.path);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
// Use (no title) for non-standard URIs (data:, javascript:, ...)
|
|
|
|
title = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
title = aNode.title;
|
|
|
|
|
2008-03-13 12:25:49 -07:00
|
|
|
return title || this.getString("noTitle");
|
2008-03-11 01:15:32 -07:00
|
|
|
},
|
|
|
|
|
2007-11-26 11:04:23 -08:00
|
|
|
get leftPaneQueries() {
|
|
|
|
// build the map
|
|
|
|
this.leftPaneFolderId;
|
|
|
|
return this.leftPaneQueries;
|
|
|
|
},
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// get the folder id for the organizer left-pane folder
|
|
|
|
get leftPaneFolderId() {
|
|
|
|
var leftPaneRoot = -1;
|
|
|
|
var allBookmarksId;
|
2008-04-20 19:35:16 -07:00
|
|
|
var items = PlacesUtils.annotations
|
|
|
|
.getItemsWithAnnotation(ORGANIZER_FOLDER_ANNO, {});
|
|
|
|
if (items.length != 0 && items[0] != -1) {
|
2008-01-29 10:10:59 -08:00
|
|
|
leftPaneRoot = items[0];
|
2008-04-20 19:35:16 -07:00
|
|
|
// check organizer left pane version
|
|
|
|
var version = PlacesUtils.annotations
|
|
|
|
.getItemAnnotation(leftPaneRoot, ORGANIZER_FOLDER_ANNO);
|
|
|
|
if (version != ORGANIZER_LEFTPANE_VERSION) {
|
|
|
|
// If version is not valid we must rebuild the left pane.
|
|
|
|
PlacesUtils.bookmarks.removeFolder(leftPaneRoot);
|
|
|
|
leftPaneRoot = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-29 10:10:59 -08:00
|
|
|
if (leftPaneRoot != -1) {
|
|
|
|
// Build the leftPaneQueries Map
|
|
|
|
delete this.leftPaneQueries;
|
|
|
|
this.leftPaneQueries = {};
|
2008-04-20 19:35:16 -07:00
|
|
|
var items = PlacesUtils.annotations
|
|
|
|
.getItemsWithAnnotation(ORGANIZER_QUERY_ANNO, {});
|
2008-01-29 10:10:59 -08:00
|
|
|
for (var i=0; i < items.length; i++) {
|
2008-03-13 12:25:49 -07:00
|
|
|
var queryName = PlacesUtils.annotations
|
|
|
|
.getItemAnnotation(items[i], ORGANIZER_QUERY_ANNO);
|
2008-01-29 10:10:59 -08:00
|
|
|
this.leftPaneQueries[queryName] = items[i];
|
2007-11-26 11:04:23 -08:00
|
|
|
}
|
2008-01-29 10:10:59 -08:00
|
|
|
delete this.leftPaneFolderId;
|
|
|
|
return this.leftPaneFolderId = leftPaneRoot;
|
2007-11-19 18:01:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
2008-03-13 12:25:49 -07:00
|
|
|
const EXPIRE_NEVER = PlacesUtils.annotations.EXPIRE_NEVER;
|
2007-11-19 18:01:53 -08:00
|
|
|
var callback = {
|
|
|
|
runBatched: function(aUserData) {
|
2007-11-26 11:04:23 -08:00
|
|
|
delete self.leftPaneQueries;
|
|
|
|
self.leftPaneQueries = { };
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// Left Pane Root Folder
|
2008-03-13 12:25:49 -07:00
|
|
|
leftPaneRoot = PlacesUtils.bookmarks.createFolder(PlacesUtils.placesRootId, "", -1);
|
2008-04-25 14:36:40 -07:00
|
|
|
// ensure immediate children can't be removed
|
|
|
|
PlacesUtils.bookmarks.setFolderReadonly(leftPaneRoot, true);
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
// History Query
|
2008-03-13 12:25:49 -07:00
|
|
|
let uri = PlacesUtils._uri("place:sort=4&");
|
2007-11-19 18:01:53 -08:00
|
|
|
let title = self.getString("OrganizerQueryHistory");
|
2008-03-13 12:25:49 -07:00
|
|
|
let itemId = PlacesUtils.bookmarks.insertBookmark(leftPaneRoot, uri, -1, title);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(itemId, ORGANIZER_QUERY_ANNO,
|
|
|
|
"History", 0, EXPIRE_NEVER);
|
2007-11-26 11:04:23 -08:00
|
|
|
self.leftPaneQueries["History"] = itemId;
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
// XXX: Downloads
|
|
|
|
|
|
|
|
// Tags Query
|
2008-04-11 09:22:01 -07:00
|
|
|
uri = PlacesUtils._uri("place:type=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_ASCENDING);
|
|
|
|
title = PlacesUtils.bookmarks.getItemTitle(PlacesUtils.tagsFolderId);
|
|
|
|
itemId = PlacesUtils.bookmarks.insertBookmark(leftPaneRoot, uri, -1, title);
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(itemId, ORGANIZER_QUERY_ANNO,
|
|
|
|
"Tags", 0, EXPIRE_NEVER);
|
2007-11-26 11:04:23 -08:00
|
|
|
self.leftPaneQueries["Tags"] = itemId;
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
// All Bookmarks Folder
|
|
|
|
title = self.getString("OrganizerQueryAllBookmarks");
|
2008-03-13 12:25:49 -07:00
|
|
|
itemId = PlacesUtils.bookmarks.createFolder(leftPaneRoot, title, -1);
|
2007-11-19 18:01:53 -08:00
|
|
|
allBookmarksId = itemId;
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(itemId, ORGANIZER_QUERY_ANNO,
|
|
|
|
"AllBookmarks", 0, EXPIRE_NEVER);
|
2007-11-26 11:04:23 -08:00
|
|
|
self.leftPaneQueries["AllBookmarks"] = itemId;
|
2007-11-19 18:01:53 -08:00
|
|
|
|
2008-04-23 09:00:42 -07:00
|
|
|
// disallow manipulating this folder within the organizer UI
|
|
|
|
PlacesUtils.bookmarks.setFolderReadonly(allBookmarksId, true);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
// All Bookmarks->Bookmarks Toolbar Query
|
2008-03-17 08:28:11 -07:00
|
|
|
uri = PlacesUtils._uri("place:folder=TOOLBAR");
|
2008-03-13 12:25:49 -07:00
|
|
|
itemId = PlacesUtils.bookmarks.insertBookmark(allBookmarksId, uri, -1, null);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(itemId, ORGANIZER_QUERY_ANNO,
|
|
|
|
"BookmarksToolbar", 0, EXPIRE_NEVER);
|
2007-11-26 11:04:23 -08:00
|
|
|
self.leftPaneQueries["BookmarksToolbar"] = itemId;
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
// All Bookmarks->Bookmarks Menu Query
|
2008-03-17 08:28:11 -07:00
|
|
|
uri = PlacesUtils._uri("place:folder=BOOKMARKS_MENU");
|
2008-03-13 12:25:49 -07:00
|
|
|
itemId = PlacesUtils.bookmarks.insertBookmark(allBookmarksId, uri, -1, null);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(itemId, ORGANIZER_QUERY_ANNO,
|
|
|
|
"BookmarksMenu", 0, EXPIRE_NEVER);
|
2007-11-26 11:04:23 -08:00
|
|
|
self.leftPaneQueries["BookmarksMenu"] = itemId;
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
// All Bookmarks->Unfiled bookmarks
|
2008-03-17 08:28:11 -07:00
|
|
|
uri = PlacesUtils._uri("place:folder=UNFILED_BOOKMARKS");
|
2008-03-13 12:25:49 -07:00
|
|
|
itemId = PlacesUtils.bookmarks.insertBookmark(allBookmarksId, uri, -1, null);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(itemId, ORGANIZER_QUERY_ANNO,
|
|
|
|
"UnfiledBookmarks", 0,
|
|
|
|
EXPIRE_NEVER);
|
2007-11-26 11:04:23 -08:00
|
|
|
self.leftPaneQueries["UnfiledBookmarks"] = itemId;
|
2007-11-19 18:01:53 -08:00
|
|
|
|
|
|
|
// disallow manipulating this folder within the organizer UI
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUtils.bookmarks.setFolderReadonly(leftPaneRoot, true);
|
2007-11-19 18:01:53 -08:00
|
|
|
}
|
|
|
|
};
|
2008-03-13 12:25:49 -07:00
|
|
|
PlacesUtils.bookmarks.runInBatchMode(callback, null);
|
2008-04-20 19:35:16 -07:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(leftPaneRoot,
|
|
|
|
ORGANIZER_FOLDER_ANNO,
|
|
|
|
ORGANIZER_LEFTPANE_VERSION,
|
|
|
|
0, EXPIRE_NEVER);
|
2007-11-19 18:01:53 -08:00
|
|
|
delete this.leftPaneFolderId;
|
|
|
|
return this.leftPaneFolderId = leftPaneRoot;
|
|
|
|
},
|
|
|
|
|
|
|
|
get allBookmarksFolderId() {
|
|
|
|
// ensure the left-pane root is initialized;
|
|
|
|
this.leftPaneFolderId;
|
|
|
|
delete this.allBookmarksFolderId;
|
2007-11-26 11:04:23 -08:00
|
|
|
return this.allBookmarksFolderId = this.leftPaneQueries["AllBookmarks"];
|
2008-09-25 03:30:33 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add, update or remove the livemark status menuitem.
|
|
|
|
* @param aPopup
|
|
|
|
* The livemark container popup
|
|
|
|
*/
|
|
|
|
ensureLivemarkStatusMenuItem:
|
|
|
|
function PU_ensureLivemarkStatusMenuItem(aPopup) {
|
|
|
|
var itemId = aPopup._resultNode.itemId;
|
|
|
|
|
|
|
|
var lmStatus = null;
|
|
|
|
if (PlacesUtils.annotations
|
|
|
|
.itemHasAnnotation(itemId, "livemark/loadfailed"))
|
|
|
|
lmStatus = "bookmarksLivemarkFailed";
|
|
|
|
else if (PlacesUtils.annotations
|
|
|
|
.itemHasAnnotation(itemId, "livemark/loading"))
|
|
|
|
lmStatus = "bookmarksLivemarkLoading";
|
|
|
|
|
|
|
|
if (lmStatus && !aPopup._lmStatusMenuItem) {
|
|
|
|
// Create the status menuitem and cache it in the popup object.
|
|
|
|
aPopup._lmStatusMenuItem = document.createElement("menuitem");
|
|
|
|
aPopup._lmStatusMenuItem.setAttribute("lmStatus", lmStatus);
|
|
|
|
aPopup._lmStatusMenuItem.setAttribute("label", this.getString(lmStatus));
|
|
|
|
aPopup._lmStatusMenuItem.setAttribute("disabled", true);
|
|
|
|
aPopup.insertBefore(aPopup._lmStatusMenuItem,
|
|
|
|
aPopup.childNodes[aPopup._startMarker + 1]);
|
|
|
|
aPopup._startMarker++;
|
|
|
|
}
|
|
|
|
else if (lmStatus &&
|
|
|
|
aPopup._lmStatusMenuItem.getAttribute("lmStatus") != lmStatus) {
|
|
|
|
// Status has changed, update the cached status menuitem.
|
|
|
|
aPopup._lmStatusMenuItem.setAttribute("label",
|
|
|
|
this.getString(lmStatus));
|
|
|
|
}
|
|
|
|
else if (!lmStatus && aPopup._lmStatusMenuItem){
|
|
|
|
// No status, remove the cached menuitem.
|
|
|
|
aPopup.removeChild(aPopup._lmStatusMenuItem);
|
|
|
|
aPopup._lmStatusMenuItem = null;
|
|
|
|
aPopup._startMarker--;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|