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";
|
2009-04-02 16:41:20 -07:00
|
|
|
const ORGANIZER_LEFTPANE_VERSION = 6;
|
2009-01-21 03:39:07 -08:00
|
|
|
const EXCLUDE_FROM_BACKUP_ANNO = "places/excludeFromBackup";
|
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;
|
|
|
|
},
|
|
|
|
|
2009-04-03 11:55:37 -07:00
|
|
|
get privateBrowsing() {
|
|
|
|
delete this.privateBrowsing;
|
|
|
|
return this.privateBrowsing = Cc["@mozilla.org/privatebrowsing;1"].
|
|
|
|
getService(Ci.nsIPrivateBrowsingService);
|
|
|
|
},
|
|
|
|
|
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
|
2009-11-02 13:04:15 -08:00
|
|
|
var storedTags = PlacesUtils.tagging.getTagsForURI(itemURL);
|
2008-03-26 18:58:52 -07:00
|
|
|
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
|
2009-09-11 06:25:24 -07:00
|
|
|
if (aContainer == PlacesUtils.tagsFolderId) {
|
2008-03-13 12:25:49 -07:00
|
|
|
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);
|
2009-09-11 06:25:24 -07:00
|
|
|
// Otherwise move the item.
|
|
|
|
return this.ptm.moveItem(data.id, container, index);
|
2008-03-13 12:25:49 -07:00
|
|
|
break;
|
|
|
|
case PlacesUtils.TYPE_X_MOZ_PLACE:
|
2009-09-11 06:25:24 -07:00
|
|
|
if (data.id == -1) // Not bookmarked.
|
2008-03-13 12:25:49 -07:00
|
|
|
return this._getURIItemCopyTransaction(data, container, index);
|
|
|
|
|
2009-09-11 06:25:24 -07:00
|
|
|
if (copy)
|
|
|
|
return this._getBookmarkItemCopyTransaction(data, container, index);
|
|
|
|
// Otherwise move the item.
|
|
|
|
return this.ptm.moveItem(data.id, container, index);
|
2008-03-13 12:25:49 -07:00
|
|
|
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);
|
2009-09-11 06:25:24 -07:00
|
|
|
// Otherwise move the item.
|
2008-04-03 09:23:45 -07:00
|
|
|
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 ||
|
2009-02-19 04:00:05 -08:00
|
|
|
type == PlacesUtils.TYPE_UNICODE ||
|
|
|
|
type == TAB_DROP_TYPE) {
|
|
|
|
var title = (type != PlacesUtils.TYPE_UNICODE) ? data.title :
|
2008-09-19 08:47:45 -07:00
|
|
|
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;
|
2009-06-12 05:59:04 -07:00
|
|
|
// Hide the Tags field if we are adding a keyword.
|
2008-10-30 10:21:47 -07:00
|
|
|
info.hiddenRows.push("tags");
|
2009-06-12 05:59:04 -07:00
|
|
|
// Keyword related params.
|
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"
|
2009-03-18 07:23:56 -07:00
|
|
|
* @param [optional] aReadOnly
|
|
|
|
* states if properties dialog should be readonly
|
2007-03-22 10:30:00 -07:00
|
|
|
* @return true if any transaction has been performed.
|
|
|
|
*/
|
2009-03-18 07:23:56 -07:00
|
|
|
showItemProperties: function PU_showItemProperties(aItemId, aType, aReadOnly) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var info = {
|
|
|
|
action: "edit",
|
2008-04-28 02:41:18 -07:00
|
|
|
type: aType,
|
2009-03-18 07:23:56 -07:00
|
|
|
itemId: aItemId,
|
|
|
|
readOnly: aReadOnly
|
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) {
|
2009-01-18 02:36:01 -08:00
|
|
|
if (!aItemsToOpen.length)
|
|
|
|
return;
|
|
|
|
|
2007-12-27 17:53:59 -08:00
|
|
|
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;
|
2009-09-20 03:58:27 -07:00
|
|
|
browserWindow.gBrowser.loadTabs(urls, loadInBackground, replaceCurrentTab);
|
2007-09-02 12:03:24 -07:00
|
|
|
},
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-03-12 06:05:48 -07:00
|
|
|
/**
|
|
|
|
* Helper for guessing scheme from an url string.
|
|
|
|
* Used to avoid nsIURI overhead in frequently called UI functions.
|
|
|
|
*
|
|
|
|
* @param aUrlString the url to guess the scheme from.
|
|
|
|
*
|
|
|
|
* @return guessed scheme for this url string.
|
|
|
|
*
|
|
|
|
* @note this is not supposed be perfect, so use it only for UI purposes.
|
|
|
|
*/
|
|
|
|
guessUrlSchemeForUI: function PUU_guessUrlSchemeForUI(aUrlString) {
|
|
|
|
return aUrlString.substr(0, aUrlString.indexOf(":"));
|
|
|
|
},
|
|
|
|
|
2007-10-24 19:02:28 -07:00
|
|
|
/**
|
|
|
|
* Helper for the toolbar and menu views
|
|
|
|
*/
|
2008-03-13 12:25:49 -07:00
|
|
|
createMenuItemForNode:
|
2009-10-01 09:53:26 -07:00
|
|
|
function PUU_createMenuItemForNode(aNode) {
|
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 {
|
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";
|
2009-03-12 06:14:12 -07:00
|
|
|
element.setAttribute("scheme", this.guessUrlSchemeForUI(aNode.uri));
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
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);
|
|
|
|
element.className = "menu-iconic bookmark-item";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw "Unexpected node";
|
|
|
|
|
2008-03-11 01:15:32 -07:00
|
|
|
element.setAttribute("label", this.getBestTitle(aNode));
|
|
|
|
|
2009-10-01 09:53:26 -07:00
|
|
|
var icon = aNode.icon;
|
|
|
|
if (icon)
|
|
|
|
element.setAttribute("image", icon);
|
2007-10-24 19:02:28 -07:00
|
|
|
}
|
|
|
|
element.node = aNode;
|
2009-10-01 09:53:26 -07:00
|
|
|
element.node._DOMElement = element;
|
2007-10-24 19:02:28 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2009-04-30 09:52:40 -07:00
|
|
|
// Get the folder id for the organizer left-pane folder.
|
2007-11-19 18:01:53 -08:00
|
|
|
get leftPaneFolderId() {
|
2009-11-06 07:25:08 -08:00
|
|
|
let leftPaneRoot = -1;
|
|
|
|
let allBookmarksId;
|
2009-04-30 09:52:40 -07:00
|
|
|
|
|
|
|
// Shortcuts to services.
|
2009-11-06 07:25:08 -08:00
|
|
|
let bs = PlacesUtils.bookmarks;
|
|
|
|
let as = PlacesUtils.annotations;
|
|
|
|
|
|
|
|
// This is the list of the left pane queries.
|
|
|
|
let queries = {
|
|
|
|
"PlacesRoot": { title: "" },
|
|
|
|
"History": { title: this.getString("OrganizerQueryHistory") },
|
|
|
|
"Tags": { title: this.getString("OrganizerQueryTags") },
|
|
|
|
"AllBookmarks": { title: this.getString("OrganizerQueryAllBookmarks") },
|
|
|
|
"BookmarksToolbar":
|
|
|
|
{ title: null,
|
|
|
|
concreteTitle: PlacesUtils.getString("BookmarksToolbarFolderTitle"),
|
|
|
|
concreteId: PlacesUtils.toolbarFolderId },
|
|
|
|
"BookmarksMenu":
|
|
|
|
{ title: null,
|
|
|
|
concreteTitle: PlacesUtils.getString("BookmarksMenuFolderTitle"),
|
|
|
|
concreteId: PlacesUtils.bookmarksMenuFolderId },
|
|
|
|
"UnfiledBookmarks":
|
|
|
|
{ title: null,
|
|
|
|
concreteTitle: PlacesUtils.getString("UnsortedBookmarksFolderTitle"),
|
|
|
|
concreteId: PlacesUtils.unfiledBookmarksFolderId },
|
|
|
|
};
|
|
|
|
// All queries but PlacesRoot.
|
|
|
|
const EXPECTED_QUERY_COUNT = 6;
|
|
|
|
|
|
|
|
// Removes an item and associated annotations, ignoring eventual errors.
|
|
|
|
function safeRemoveItem(aItemId) {
|
|
|
|
try {
|
|
|
|
if (as.itemHasAnnotation(aItemId, ORGANIZER_QUERY_ANNO) &&
|
|
|
|
!(as.getItemAnnotation(aItemId, ORGANIZER_QUERY_ANNO) in queries)) {
|
|
|
|
// Some extension annotated their roots with our query annotation,
|
|
|
|
// so we should not delete them.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// removeItemAnnotation does not check if item exists, nor the anno,
|
|
|
|
// so this is safe to do.
|
|
|
|
as.removeItemAnnotation(aItemId, ORGANIZER_FOLDER_ANNO);
|
|
|
|
as.removeItemAnnotation(aItemId, ORGANIZER_QUERY_ANNO);
|
|
|
|
// This will throw if the annotation is an orphan.
|
|
|
|
bs.removeItem(aItemId);
|
|
|
|
}
|
|
|
|
catch(e) { /* orphan anno */ }
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns true if item really exists, false otherwise.
|
|
|
|
function itemExists(aItemId) {
|
|
|
|
try {
|
|
|
|
bs.getItemIndex(aItemId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-04-30 09:52:40 -07:00
|
|
|
|
2009-11-06 07:25:08 -08:00
|
|
|
// Get all items marked as being the left pane folder.
|
|
|
|
let items = as.getItemsWithAnnotation(ORGANIZER_FOLDER_ANNO, {});
|
2009-01-21 03:39:07 -08:00
|
|
|
if (items.length > 1) {
|
|
|
|
// Something went wrong, we cannot have more than one left pane folder,
|
2009-04-30 09:52:40 -07:00
|
|
|
// remove all left pane folders and continue. We will create a new one.
|
2009-11-06 07:25:08 -08:00
|
|
|
items.forEach(safeRemoveItem);
|
2009-01-21 03:39:07 -08:00
|
|
|
}
|
|
|
|
else if (items.length == 1 && items[0] != -1) {
|
2008-01-29 10:10:59 -08:00
|
|
|
leftPaneRoot = items[0];
|
2009-11-06 07:25:08 -08:00
|
|
|
|
|
|
|
// Check that organizer left pane root is valid.
|
|
|
|
let version = as.getItemAnnotation(leftPaneRoot, ORGANIZER_FOLDER_ANNO);
|
|
|
|
if (version != ORGANIZER_LEFTPANE_VERSION || !itemExists(leftPaneRoot)) {
|
|
|
|
// Invalid root, we must rebuild the left pane.
|
|
|
|
safeRemoveItem(leftPaneRoot);
|
2008-04-20 19:35:16 -07:00
|
|
|
leftPaneRoot = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-29 10:10:59 -08:00
|
|
|
if (leftPaneRoot != -1) {
|
2009-04-30 09:52:40 -07:00
|
|
|
// A valid left pane folder has been found.
|
2009-11-06 07:25:08 -08:00
|
|
|
// Build the leftPaneQueries Map. This is used to quickly access them,
|
2009-04-30 09:52:40 -07:00
|
|
|
// associating a mnemonic name to the real item ids.
|
2008-01-29 10:10:59 -08:00
|
|
|
delete this.leftPaneQueries;
|
|
|
|
this.leftPaneQueries = {};
|
2009-11-06 07:25:08 -08:00
|
|
|
|
|
|
|
let items = as.getItemsWithAnnotation(ORGANIZER_QUERY_ANNO, {});
|
|
|
|
// While looping through queries we will also check for their validity.
|
|
|
|
let queriesCount = 0;
|
|
|
|
for(let i = 0; i < items.length; i++) {
|
|
|
|
let queryName = as.getItemAnnotation(items[i], ORGANIZER_QUERY_ANNO);
|
|
|
|
// Some extension did use our annotation to decorate their items
|
|
|
|
// with icons, so we should check only our elements, to avoid dataloss.
|
|
|
|
if (!(queryName in queries))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
let query = queries[queryName];
|
|
|
|
query.itemId = items[i];
|
|
|
|
|
|
|
|
if (!itemExists(query.itemId)) {
|
|
|
|
// Orphan annotation, bail out and create a new left pane root.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that all queries have valid parents.
|
|
|
|
let parentId = bs.getFolderIdForItem(query.itemId);
|
|
|
|
if (items.indexOf(parentId) == -1 && parentId != leftPaneRoot) {
|
|
|
|
// The parent is not part of the left pane, bail out and create a new
|
|
|
|
// left pane root.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-30 09:52:40 -07:00
|
|
|
// Titles could have been corrupted or the user could have changed his
|
2009-11-06 07:25:08 -08:00
|
|
|
// locale. Check title and eventually fix it.
|
|
|
|
if (bs.getItemTitle(query.itemId) != query.title)
|
|
|
|
bs.setItemTitle(query.itemId, query.title);
|
|
|
|
if ("concreteId" in query) {
|
|
|
|
if (bs.getItemTitle(query.concreteId) != query.concreteTitle)
|
|
|
|
bs.setItemTitle(query.concreteId, query.concreteTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the query to our cache.
|
|
|
|
this.leftPaneQueries[queryName] = query.itemId;
|
|
|
|
queriesCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (queriesCount != EXPECTED_QUERY_COUNT) {
|
|
|
|
// Queries number is wrong, so the left pane must be corrupt.
|
|
|
|
// Note: we can't just remove the leftPaneRoot, because some query could
|
|
|
|
// have a bad parent, so we have to remove all items one by one.
|
|
|
|
items.forEach(safeRemoveItem);
|
|
|
|
safeRemoveItem(leftPaneRoot);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Everything is fine, return the current left pane folder.
|
|
|
|
delete this.leftPaneFolderId;
|
|
|
|
return this.leftPaneFolderId = leftPaneRoot;
|
2007-11-26 11:04:23 -08:00
|
|
|
}
|
2007-11-19 18:01:53 -08:00
|
|
|
}
|
|
|
|
|
2009-11-06 07:25:08 -08:00
|
|
|
// Create a new left pane folder.
|
2007-11-19 18:01:53 -08:00
|
|
|
var self = this;
|
|
|
|
var callback = {
|
2009-04-30 09:52:40 -07:00
|
|
|
// Helper to create an organizer special query.
|
|
|
|
create_query: function CB_create_query(aQueryName, aParentId, aQueryUrl) {
|
|
|
|
let itemId = bs.insertBookmark(aParentId,
|
|
|
|
PlacesUtils._uri(aQueryUrl),
|
|
|
|
bs.DEFAULT_INDEX,
|
2009-11-06 07:25:08 -08:00
|
|
|
queries[aQueryName].title);
|
2009-04-30 09:52:40 -07:00
|
|
|
// Mark as special organizer query.
|
|
|
|
as.setItemAnnotation(itemId, ORGANIZER_QUERY_ANNO, aQueryName,
|
|
|
|
0, as.EXPIRE_NEVER);
|
|
|
|
// We should never backup this, since it changes between profiles.
|
|
|
|
as.setItemAnnotation(itemId, EXCLUDE_FROM_BACKUP_ANNO, 1,
|
|
|
|
0, as.EXPIRE_NEVER);
|
|
|
|
// Add to the queries map.
|
|
|
|
self.leftPaneQueries[aQueryName] = itemId;
|
|
|
|
return itemId;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Helper to create an organizer special folder.
|
|
|
|
create_folder: function CB_create_folder(aFolderName, aParentId, aIsRoot) {
|
|
|
|
// Left Pane Root Folder.
|
|
|
|
let folderId = bs.createFolder(aParentId,
|
2009-11-06 07:25:08 -08:00
|
|
|
queries[aFolderName].title,
|
2009-04-30 09:52:40 -07:00
|
|
|
bs.DEFAULT_INDEX);
|
|
|
|
// We should never backup this, since it changes between profiles.
|
|
|
|
as.setItemAnnotation(folderId, EXCLUDE_FROM_BACKUP_ANNO, 1,
|
|
|
|
0, as.EXPIRE_NEVER);
|
|
|
|
// Disallow manipulating this folder within the organizer UI.
|
|
|
|
bs.setFolderReadonly(folderId, true);
|
|
|
|
|
|
|
|
if (aIsRoot) {
|
|
|
|
// Mark as special left pane root.
|
|
|
|
as.setItemAnnotation(folderId, ORGANIZER_FOLDER_ANNO,
|
|
|
|
ORGANIZER_LEFTPANE_VERSION,
|
|
|
|
0, as.EXPIRE_NEVER);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Mark as special organizer folder.
|
|
|
|
as.setItemAnnotation(folderId, ORGANIZER_QUERY_ANNO, aFolderName,
|
|
|
|
0, as.EXPIRE_NEVER);
|
|
|
|
self.leftPaneQueries[aFolderName] = folderId;
|
|
|
|
}
|
|
|
|
return folderId;
|
|
|
|
},
|
|
|
|
|
|
|
|
runBatched: function CB_runBatched(aUserData) {
|
2007-11-26 11:04:23 -08:00
|
|
|
delete self.leftPaneQueries;
|
|
|
|
self.leftPaneQueries = { };
|
|
|
|
|
2009-04-30 09:52:40 -07:00
|
|
|
// Left Pane Root Folder.
|
|
|
|
leftPaneRoot = this.create_folder("PlacesRoot", bs.placesRoot, true);
|
|
|
|
|
|
|
|
// History Query.
|
|
|
|
this.create_query("History", leftPaneRoot,
|
|
|
|
"place:type=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.RESULTS_AS_DATE_QUERY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_DATE_DESCENDING);
|
|
|
|
|
|
|
|
// XXX: Downloads.
|
|
|
|
|
|
|
|
// Tags Query.
|
|
|
|
this.create_query("Tags", leftPaneRoot,
|
|
|
|
"place:type=" +
|
2008-04-11 09:22:01 -07:00
|
|
|
Ci.nsINavHistoryQueryOptions.RESULTS_AS_TAG_QUERY +
|
|
|
|
"&sort=" +
|
|
|
|
Ci.nsINavHistoryQueryOptions.SORT_BY_TITLE_ASCENDING);
|
2009-04-30 09:52:40 -07:00
|
|
|
|
|
|
|
// All Bookmarks Folder.
|
|
|
|
allBookmarksId = this.create_folder("AllBookmarks", leftPaneRoot, false);
|
|
|
|
|
|
|
|
// All Bookmarks->Bookmarks Toolbar Query.
|
|
|
|
this.create_query("BookmarksToolbar", allBookmarksId,
|
|
|
|
"place:folder=TOOLBAR");
|
|
|
|
|
|
|
|
// All Bookmarks->Bookmarks Menu Query.
|
|
|
|
this.create_query("BookmarksMenu", allBookmarksId,
|
|
|
|
"place:folder=BOOKMARKS_MENU");
|
|
|
|
|
|
|
|
// All Bookmarks->Unfiled Bookmarks Query.
|
|
|
|
this.create_query("UnfiledBookmarks", allBookmarksId,
|
|
|
|
"place:folder=UNFILED_BOOKMARKS");
|
2007-11-19 18:01:53 -08:00
|
|
|
}
|
|
|
|
};
|
2009-04-30 09:52:40 -07:00
|
|
|
bs.runInBatchMode(callback, null);
|
|
|
|
|
2007-11-19 18:01:53 -08:00
|
|
|
delete this.leftPaneFolderId;
|
|
|
|
return this.leftPaneFolderId = leftPaneRoot;
|
|
|
|
},
|
|
|
|
|
2009-06-12 15:21:47 -07:00
|
|
|
/**
|
|
|
|
* Get the folder id for the organizer left-pane folder.
|
|
|
|
*/
|
2007-11-19 18:01:53 -08:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2009-06-12 15:21:47 -07:00
|
|
|
/**
|
|
|
|
* If an item is a left-pane query, returns the name of the query
|
|
|
|
* or an empty string if not.
|
|
|
|
*
|
|
|
|
* @param aItemId id of a container
|
|
|
|
* @returns the name of the query, or empty string if not a left-pane query
|
|
|
|
*/
|
|
|
|
getLeftPaneQueryNameFromId: function PU_getLeftPaneQueryNameFromId(aItemId) {
|
|
|
|
var queryName = "";
|
|
|
|
// If the let pane hasn't been built, use the annotation service
|
|
|
|
// directly, to avoid building the left pane too early.
|
|
|
|
if (this.__lookupGetter__("leftPaneFolderId")) {
|
|
|
|
try {
|
|
|
|
queryName = PlacesUtils.annotations.
|
2009-10-06 06:04:14 -07:00
|
|
|
getItemAnnotation(aItemId, ORGANIZER_QUERY_ANNO);
|
2009-06-12 15:21:47 -07:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
// doesn't have the annotation
|
|
|
|
queryName = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If the left pane has already been built, use the name->id map
|
|
|
|
// cached in PlacesUIUtils.
|
|
|
|
for (let [name, id] in Iterator(this.leftPaneQueries)) {
|
|
|
|
if (aItemId == id)
|
|
|
|
queryName = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return queryName;
|
|
|
|
},
|
|
|
|
|
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,
|
2009-06-29 09:47:03 -07:00
|
|
|
aPopup.childNodes.item(aPopup._startMarker + 1));
|
2008-09-25 03:30:33 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
};
|