2008-06-07 06:28:01 +04:00
|
|
|
/* ***** 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 Bookmarks Sync.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dan Mills <thunder@mozilla.com>
|
|
|
|
* Jono DiCarlo <jdicarlo@mozilla.org>
|
2008-08-05 04:23:23 +04:00
|
|
|
* Anant Narayanan <anant@kix.in>
|
2008-06-07 06:28:01 +04: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 ***** */
|
|
|
|
|
2008-07-01 05:50:06 +04:00
|
|
|
const EXPORTED_SYMBOLS = ['BookmarksEngine', 'BookmarksSharingManager'];
|
2008-06-03 23:38:48 +04:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2009-08-15 12:00:46 +04:00
|
|
|
const PARENT_ANNO = "weave/parent";
|
2009-08-16 23:39:15 +04:00
|
|
|
const PREDECESSOR_ANNO = "weave/predecessor";
|
2008-12-12 01:26:20 +03:00
|
|
|
const SERVICE_NOT_SUPPORTED = "Service not supported on this platform";
|
|
|
|
|
2009-09-01 04:29:47 +04:00
|
|
|
Cu.import("resource://gre/modules/utils.js");
|
2008-06-29 22:44:27 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2009-12-03 06:20:44 +03:00
|
|
|
Cu.import("resource://weave/ext/Observers.js");
|
2008-06-03 23:38:48 +04:00
|
|
|
Cu.import("resource://weave/util.js");
|
|
|
|
Cu.import("resource://weave/engines.js");
|
|
|
|
Cu.import("resource://weave/stores.js");
|
|
|
|
Cu.import("resource://weave/trackers.js");
|
2008-12-29 06:59:44 +03:00
|
|
|
Cu.import("resource://weave/type_records/bookmark.js");
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2009-06-17 20:28:15 +04:00
|
|
|
// Lazily initialize the special top level folders
|
|
|
|
let kSpecialIds = {};
|
|
|
|
[["menu", "bookmarksMenuFolder"],
|
|
|
|
["places", "placesRoot"],
|
|
|
|
["tags", "tagsFolder"],
|
|
|
|
["toolbar", "toolbarFolder"],
|
|
|
|
["unfiled", "unfiledBookmarksFolder"],
|
2009-08-15 11:59:49 +04:00
|
|
|
].forEach(function([guid, placeName]) {
|
|
|
|
Utils.lazy2(kSpecialIds, guid, function() Svc.Bookmark[placeName]);
|
2009-06-17 20:28:15 +04:00
|
|
|
});
|
2009-12-11 03:12:14 +03:00
|
|
|
Utils.lazy2(kSpecialIds, "mobile", function() {
|
|
|
|
// Use the (one) mobile root if it already exists
|
|
|
|
let anno = "mobile/bookmarksRoot";
|
|
|
|
let root = Svc.Annos.getItemsWithAnnotation(anno, {});
|
|
|
|
if (root.length != 0)
|
|
|
|
return root[0];
|
|
|
|
|
|
|
|
// Create the special mobile folder to store mobile bookmarks
|
|
|
|
let mobile = Svc.Bookmark.createFolder(Svc.Bookmark.placesRoot, "mobile", -1);
|
|
|
|
Utils.anno(mobile, anno, 1);
|
|
|
|
return mobile;
|
|
|
|
});
|
2009-06-17 20:28:15 +04:00
|
|
|
|
2009-08-15 11:59:49 +04:00
|
|
|
// Create some helper functions to convert GUID/ids
|
|
|
|
function idForGUID(guid) {
|
|
|
|
if (guid in kSpecialIds)
|
|
|
|
return kSpecialIds[guid];
|
|
|
|
return Svc.Bookmark.getItemIdForGUID(guid);
|
|
|
|
}
|
|
|
|
function GUIDForId(placeId) {
|
|
|
|
for (let [guid, id] in Iterator(kSpecialIds))
|
|
|
|
if (placeId == id)
|
|
|
|
return guid;
|
|
|
|
return Svc.Bookmark.getItemGUID(placeId);
|
|
|
|
}
|
|
|
|
|
2008-12-09 23:26:14 +03:00
|
|
|
function BookmarksEngine() {
|
2010-02-12 02:29:15 +03:00
|
|
|
SyncEngine.call(this, "Bookmarks");
|
2010-02-12 02:25:31 +03:00
|
|
|
this._handleImport();
|
2008-06-25 08:15:14 +04:00
|
|
|
}
|
|
|
|
BookmarksEngine.prototype = {
|
2008-12-05 11:39:54 +03:00
|
|
|
__proto__: SyncEngine.prototype,
|
2009-04-13 23:54:31 +04:00
|
|
|
_recordObj: PlacesItem,
|
2009-01-07 00:54:18 +03:00
|
|
|
_storeObj: BookmarksStore,
|
2009-07-30 22:52:26 +04:00
|
|
|
_trackerObj: BookmarksTracker,
|
|
|
|
|
2009-12-03 06:20:44 +03:00
|
|
|
_handleImport: function _handleImport() {
|
|
|
|
Observers.add("bookmarks-restore-begin", function() {
|
|
|
|
this._log.debug("Ignoring changes from importing bookmarks");
|
|
|
|
this._tracker.ignoreAll = true;
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
Observers.add("bookmarks-restore-success", function() {
|
|
|
|
this._log.debug("Triggering fresh start on successful import");
|
|
|
|
this.resetLastSync();
|
|
|
|
this._tracker.ignoreAll = false;
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
Observers.add("bookmarks-restore-failed", function() {
|
|
|
|
this._tracker.ignoreAll = false;
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2009-09-01 05:04:40 +04:00
|
|
|
_sync: Utils.batchSync("Bookmark", SyncEngine),
|
2009-09-01 04:27:30 +04:00
|
|
|
|
2009-09-01 04:54:21 +04:00
|
|
|
_syncStartup: function _syncStart() {
|
|
|
|
SyncEngine.prototype._syncStartup.call(this);
|
|
|
|
|
2009-09-09 10:33:58 +04:00
|
|
|
// Lazily create a mapping of folder titles and separator positions to GUID
|
2009-11-20 08:34:17 +03:00
|
|
|
this.__defineGetter__("_lazyMap", function() {
|
|
|
|
delete this._lazyMap;
|
2009-09-01 04:54:21 +04:00
|
|
|
|
2009-11-20 08:34:17 +03:00
|
|
|
let lazyMap = {};
|
2009-09-01 04:54:21 +04:00
|
|
|
for (let guid in this._store.getAllIDs()) {
|
2009-11-20 08:34:17 +03:00
|
|
|
// Figure out what key to store the mapping
|
|
|
|
let key;
|
2009-09-01 04:54:21 +04:00
|
|
|
let id = idForGUID(guid);
|
2009-09-09 10:33:58 +04:00
|
|
|
switch (Svc.Bookmark.getItemType(id)) {
|
2010-01-25 20:33:49 +03:00
|
|
|
case Svc.Bookmark.TYPE_BOOKMARK:
|
|
|
|
key = "b" + Svc.Bookmark.getBookmarkURI(id).spec + ":" +
|
|
|
|
Svc.Bookmark.getItemTitle(id);
|
|
|
|
break;
|
2009-09-09 10:33:58 +04:00
|
|
|
case Svc.Bookmark.TYPE_FOLDER:
|
2009-11-20 08:34:17 +03:00
|
|
|
key = "f" + Svc.Bookmark.getItemTitle(id);
|
2009-09-09 10:33:58 +04:00
|
|
|
break;
|
|
|
|
case Svc.Bookmark.TYPE_SEPARATOR:
|
2009-11-20 08:34:17 +03:00
|
|
|
key = "s" + Svc.Bookmark.getItemIndex(id);
|
2009-09-09 10:33:58 +04:00
|
|
|
break;
|
2009-11-20 08:34:17 +03:00
|
|
|
default:
|
|
|
|
continue;
|
2009-09-09 10:33:58 +04:00
|
|
|
}
|
2009-11-20 08:34:17 +03:00
|
|
|
|
|
|
|
// The mapping is on a per parent-folder-name basis
|
|
|
|
let parent = Svc.Bookmark.getFolderIdForItem(id);
|
|
|
|
let parentName = Svc.Bookmark.getItemTitle(parent);
|
|
|
|
if (lazyMap[parentName] == null)
|
|
|
|
lazyMap[parentName] = {};
|
|
|
|
|
|
|
|
// Remember this item's guid for its parent-name/key pair
|
|
|
|
lazyMap[parentName][key] = guid;
|
2009-09-01 04:54:21 +04:00
|
|
|
}
|
2009-09-09 10:33:58 +04:00
|
|
|
|
2009-11-20 08:34:17 +03:00
|
|
|
// Expose a helper function to get a dupe guid for an item
|
|
|
|
return this._lazyMap = function(item) {
|
|
|
|
// Figure out if we have something to key with
|
|
|
|
let key;
|
|
|
|
switch (item.type) {
|
2010-01-25 20:33:49 +03:00
|
|
|
case "bookmark":
|
|
|
|
case "query":
|
|
|
|
case "microsummary":
|
|
|
|
key = "b" + item.bmkUri + ":" + item.title;
|
|
|
|
break;
|
2009-11-20 08:34:17 +03:00
|
|
|
case "folder":
|
|
|
|
case "livemark":
|
|
|
|
key = "f" + item.title;
|
|
|
|
break;
|
|
|
|
case "separator":
|
|
|
|
key = "s" + item.pos;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2009-09-09 10:33:58 +04:00
|
|
|
|
2009-11-20 08:34:17 +03:00
|
|
|
// Give the guid if we have the matching pair
|
2010-01-25 20:33:49 +03:00
|
|
|
this._log.trace("Finding mapping: " + item.parentName + ", " + key);
|
2009-11-20 08:34:17 +03:00
|
|
|
let parent = lazyMap[item.parentName];
|
2010-01-25 20:33:49 +03:00
|
|
|
let dupe = parent && parent[key];
|
|
|
|
this._log.trace("Mapped dupe: " + dupe);
|
|
|
|
return dupe;
|
2009-11-20 08:34:17 +03:00
|
|
|
};
|
|
|
|
});
|
2009-09-01 04:54:21 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_syncFinish: function _syncFinish() {
|
|
|
|
SyncEngine.prototype._syncFinish.call(this);
|
2009-11-20 08:34:17 +03:00
|
|
|
delete this._lazyMap;
|
2009-12-16 01:21:13 +03:00
|
|
|
this._tracker._ensureMobileQuery();
|
2009-09-01 04:54:21 +04:00
|
|
|
},
|
|
|
|
|
2009-09-01 04:27:30 +04:00
|
|
|
_findDupe: function _findDupe(item) {
|
2010-01-25 20:33:49 +03:00
|
|
|
return this._lazyMap(item);
|
2009-09-09 10:33:15 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_handleDupe: function _handleDupe(item, dupeId) {
|
|
|
|
// The local dupe has the lower id, so make it the winning id
|
|
|
|
if (dupeId < item.id)
|
|
|
|
[item.id, dupeId] = [dupeId, item.id];
|
|
|
|
|
|
|
|
// Trigger id change from dupe to winning and update the server
|
|
|
|
this._store.changeItemID(dupeId, item.id);
|
|
|
|
this._deleteId(dupeId);
|
2010-04-02 02:54:53 +04:00
|
|
|
this._tracker.addChangedID(item.id, 0);
|
2009-07-30 22:52:26 +04:00
|
|
|
}
|
2008-06-03 23:38:48 +04:00
|
|
|
};
|
|
|
|
|
2010-02-12 02:29:15 +03:00
|
|
|
function BookmarksStore(name) {
|
|
|
|
Store.call(this, name);
|
2008-06-03 23:38:48 +04:00
|
|
|
}
|
|
|
|
BookmarksStore.prototype = {
|
2008-11-07 06:18:46 +03:00
|
|
|
__proto__: Store.prototype,
|
2008-06-03 23:38:48 +04:00
|
|
|
|
|
|
|
__bms: null,
|
|
|
|
get _bms() {
|
|
|
|
if (!this.__bms)
|
|
|
|
this.__bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
|
|
|
return this.__bms;
|
|
|
|
},
|
|
|
|
|
|
|
|
__hsvc: null,
|
|
|
|
get _hsvc() {
|
|
|
|
if (!this.__hsvc)
|
|
|
|
this.__hsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
|
|
|
getService(Ci.nsINavHistoryService);
|
|
|
|
return this.__hsvc;
|
|
|
|
},
|
|
|
|
|
|
|
|
__ls: null,
|
|
|
|
get _ls() {
|
|
|
|
if (!this.__ls)
|
|
|
|
this.__ls = Cc["@mozilla.org/browser/livemark-service;2"].
|
|
|
|
getService(Ci.nsILivemarkService);
|
|
|
|
return this.__ls;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _ms() {
|
2008-12-29 06:59:44 +03:00
|
|
|
let ms;
|
|
|
|
try {
|
|
|
|
ms = Cc["@mozilla.org/microsummary/service;1"].
|
|
|
|
getService(Ci.nsIMicrosummaryService);
|
|
|
|
} catch (e) {
|
|
|
|
ms = null;
|
|
|
|
this._log.warn("Could not load microsummary service");
|
|
|
|
this._log.debug(e);
|
|
|
|
}
|
|
|
|
this.__defineGetter__("_ms", function() ms);
|
|
|
|
return ms;
|
2008-06-03 23:38:48 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
__ts: null,
|
|
|
|
get _ts() {
|
|
|
|
if (!this.__ts)
|
|
|
|
this.__ts = Cc["@mozilla.org/browser/tagging-service;1"].
|
|
|
|
getService(Ci.nsITaggingService);
|
|
|
|
return this.__ts;
|
|
|
|
},
|
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
|
2008-12-30 10:28:17 +03:00
|
|
|
itemExists: function BStore_itemExists(id) {
|
2009-08-15 11:59:49 +04:00
|
|
|
return idForGUID(id) > 0;
|
2008-11-20 03:21:12 +03:00
|
|
|
},
|
|
|
|
|
2009-09-09 10:33:15 +04:00
|
|
|
// Hash of old GUIDs to the new renamed GUIDs
|
|
|
|
aliases: {},
|
|
|
|
|
2009-08-15 12:00:32 +04:00
|
|
|
applyIncoming: function BStore_applyIncoming(record) {
|
|
|
|
// Ignore (accidental?) root changes
|
|
|
|
if (record.id in kSpecialIds) {
|
|
|
|
this._log.debug("Skipping change to root node: " + record.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-09-09 10:33:15 +04:00
|
|
|
// Convert GUID fields to the aliased GUID if necessary
|
|
|
|
["id", "parentid", "predecessorid"].forEach(function(field) {
|
|
|
|
let alias = this.aliases[record[field]];
|
|
|
|
if (alias != null)
|
|
|
|
record[field] = alias;
|
|
|
|
}, this);
|
|
|
|
|
2009-08-15 12:00:32 +04:00
|
|
|
// Preprocess the record before doing the normal apply
|
2009-07-14 04:43:15 +04:00
|
|
|
switch (record.type) {
|
|
|
|
case "query": {
|
|
|
|
// Convert the query uri if necessary
|
|
|
|
if (record.bmkUri == null || record.folderName == null)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Tag something so that the tag exists
|
|
|
|
let tag = record.folderName;
|
|
|
|
let dummyURI = Utils.makeURI("about:weave#BStore_preprocess");
|
|
|
|
this._ts.tagURI(dummyURI, [tag]);
|
|
|
|
|
|
|
|
// Look for the id of the tag (that might have just been added)
|
|
|
|
let tags = this._getNode(this._bms.tagsFolder);
|
|
|
|
if (!(tags instanceof Ci.nsINavHistoryQueryResultNode))
|
|
|
|
break;
|
|
|
|
|
|
|
|
tags.containerOpen = true;
|
|
|
|
for (let i = 0; i < tags.childCount; i++) {
|
|
|
|
let child = tags.getChild(i);
|
|
|
|
// Found the tag, so fix up the query to use the right id
|
|
|
|
if (child.title == tag) {
|
|
|
|
this._log.debug("query folder: " + tag + " = " + child.itemId);
|
|
|
|
record.bmkUri = record.bmkUri.replace(/([:&]folder=)\d+/, "$1" +
|
|
|
|
child.itemId);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-08-15 12:00:32 +04:00
|
|
|
|
2009-08-15 12:00:46 +04:00
|
|
|
// Figure out the local id of the parent GUID if available
|
|
|
|
let parentGUID = record.parentid;
|
|
|
|
record._orphan = false;
|
|
|
|
if (parentGUID != null) {
|
|
|
|
let parentId = idForGUID(parentGUID);
|
|
|
|
|
|
|
|
// Default to unfiled if we don't have the parent yet
|
|
|
|
if (parentId <= 0) {
|
|
|
|
this._log.trace("Reparenting to unfiled until parent is synced");
|
|
|
|
record._orphan = true;
|
|
|
|
parentId = kSpecialIds.unfiled;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the parent id for modifying the bookmark later
|
|
|
|
record._parent = parentId;
|
|
|
|
}
|
|
|
|
|
2009-08-16 23:39:15 +04:00
|
|
|
// Default to append unless we're not an orphan with the predecessor
|
|
|
|
let predGUID = record.predecessorid;
|
|
|
|
record._insertPos = Svc.Bookmark.DEFAULT_INDEX;
|
|
|
|
if (!record._orphan) {
|
|
|
|
// No predecessor means it's the first item
|
|
|
|
if (predGUID == null)
|
|
|
|
record._insertPos = 0;
|
|
|
|
else {
|
2009-08-19 05:36:31 +04:00
|
|
|
// The insert position is one after the predecessor of the same parent
|
2009-08-16 23:39:15 +04:00
|
|
|
let predId = idForGUID(predGUID);
|
2009-08-19 05:36:31 +04:00
|
|
|
if (predId != -1 && this._getParentGUIDForId(predId) == parentGUID) {
|
2009-08-16 23:39:15 +04:00
|
|
|
record._insertPos = Svc.Bookmark.getItemIndex(predId) + 1;
|
2009-08-19 05:36:31 +04:00
|
|
|
record._predId = predId;
|
|
|
|
}
|
2009-08-16 23:39:15 +04:00
|
|
|
else
|
|
|
|
this._log.trace("Appending to end until predecessor is synced");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-15 12:00:32 +04:00
|
|
|
// Do the normal processing of incoming records
|
|
|
|
Store.prototype.applyIncoming.apply(this, arguments);
|
2009-08-15 12:00:46 +04:00
|
|
|
|
|
|
|
// Do some post-processing if we have an item
|
|
|
|
let itemId = idForGUID(record.id);
|
|
|
|
if (itemId > 0) {
|
2009-09-12 03:44:26 +04:00
|
|
|
// Move any children that are looking for this folder as a parent
|
2009-09-09 10:33:15 +04:00
|
|
|
if (record.type == "folder")
|
|
|
|
this._reparentOrphans(itemId);
|
|
|
|
|
2009-08-15 12:00:46 +04:00
|
|
|
// Create an annotation to remember that it needs a parent
|
|
|
|
// XXX Work around Bug 510628 by prepending parenT
|
|
|
|
if (record._orphan)
|
|
|
|
Utils.anno(itemId, PARENT_ANNO, "T" + parentGUID);
|
2009-08-19 05:42:15 +04:00
|
|
|
// It's now in the right folder, so move annotated items behind this
|
|
|
|
else
|
|
|
|
this._attachFollowers(itemId);
|
2009-08-16 23:39:15 +04:00
|
|
|
|
|
|
|
// Create an annotation if we have a predecessor but no position
|
|
|
|
// XXX Work around Bug 510628 by prepending predecessoR
|
|
|
|
if (predGUID != null && record._insertPos == Svc.Bookmark.DEFAULT_INDEX)
|
|
|
|
Utils.anno(itemId, PREDECESSOR_ANNO, "R" + predGUID);
|
2009-08-15 12:00:46 +04:00
|
|
|
}
|
2009-07-14 04:43:15 +04:00
|
|
|
},
|
|
|
|
|
2009-08-15 12:07:40 +04:00
|
|
|
/**
|
|
|
|
* Find all ids of items that have a given value for an annotation
|
|
|
|
*/
|
|
|
|
_findAnnoItems: function BStore__findAnnoItems(anno, val) {
|
|
|
|
// XXX Work around Bug 510628 by prepending parenT
|
|
|
|
if (anno == PARENT_ANNO)
|
|
|
|
val = "T" + val;
|
2009-08-17 13:34:03 +04:00
|
|
|
// XXX Work around Bug 510628 by prepending predecessoR
|
|
|
|
else if (anno == PREDECESSOR_ANNO)
|
|
|
|
val = "R" + val;
|
2009-08-15 12:07:40 +04:00
|
|
|
|
|
|
|
return Svc.Annos.getItemsWithAnnotation(anno, {}).filter(function(id)
|
|
|
|
Utils.anno(id, anno) == val);
|
|
|
|
},
|
|
|
|
|
2009-09-09 10:33:15 +04:00
|
|
|
/**
|
|
|
|
* For the provided parent item, attach its children to it
|
|
|
|
*/
|
|
|
|
_reparentOrphans: function _reparentOrphans(parentId) {
|
|
|
|
// Find orphans and reunite with this folder parent
|
|
|
|
let parentGUID = GUIDForId(parentId);
|
|
|
|
let orphans = this._findAnnoItems(PARENT_ANNO, parentGUID);
|
|
|
|
|
|
|
|
this._log.debug("Reparenting orphans " + orphans + " to " + parentId);
|
|
|
|
orphans.forEach(function(orphan) {
|
|
|
|
// Append the orphan under the parent unless it's supposed to be first
|
|
|
|
let insertPos = Svc.Bookmark.DEFAULT_INDEX;
|
|
|
|
if (!Svc.Annos.itemHasAnnotation(orphan, PREDECESSOR_ANNO))
|
|
|
|
insertPos = 0;
|
|
|
|
|
|
|
|
// Move the orphan to the parent and drop the missing parent annotation
|
|
|
|
Svc.Bookmark.moveItem(orphan, parentId, insertPos);
|
|
|
|
Svc.Annos.removeItemAnnotation(orphan, PARENT_ANNO);
|
|
|
|
});
|
2009-11-21 01:34:20 +03:00
|
|
|
|
2009-09-09 10:33:15 +04:00
|
|
|
// Fix up the ordering of the now-parented items
|
|
|
|
orphans.forEach(this._attachFollowers, this);
|
|
|
|
},
|
|
|
|
|
2009-08-19 05:36:31 +04:00
|
|
|
/**
|
|
|
|
* Move an item and all of its followers to a new position until reaching an
|
|
|
|
* item that shouldn't be moved
|
|
|
|
*/
|
|
|
|
_moveItemChain: function BStore__moveItemChain(itemId, insertPos, stopId) {
|
|
|
|
let parentId = Svc.Bookmark.getFolderIdForItem(itemId);
|
|
|
|
|
|
|
|
// Keep processing the item chain until it loops to the stop item
|
|
|
|
do {
|
|
|
|
// Figure out what's next in the chain
|
|
|
|
let itemPos = Svc.Bookmark.getItemIndex(itemId);
|
|
|
|
let nextId = Svc.Bookmark.getIdForItemAt(parentId, itemPos + 1);
|
|
|
|
|
|
|
|
Svc.Bookmark.moveItem(itemId, parentId, insertPos);
|
|
|
|
this._log.trace("Moved " + itemId + " to " + insertPos);
|
|
|
|
|
|
|
|
// Prepare for the next item in the chain
|
|
|
|
insertPos = Svc.Bookmark.getItemIndex(itemId) + 1;
|
|
|
|
itemId = nextId;
|
|
|
|
|
|
|
|
// Stop if we ran off the end or the item is looking for its pred.
|
|
|
|
if (itemId == -1 || Svc.Annos.itemHasAnnotation(itemId, PREDECESSOR_ANNO))
|
|
|
|
break;
|
|
|
|
} while (itemId != stopId);
|
|
|
|
},
|
|
|
|
|
2009-08-19 05:42:15 +04:00
|
|
|
/**
|
|
|
|
* For the provided predecessor item, attach its followers to it
|
|
|
|
*/
|
|
|
|
_attachFollowers: function BStore__attachFollowers(predId) {
|
|
|
|
let predGUID = GUIDForId(predId);
|
|
|
|
let followers = this._findAnnoItems(PREDECESSOR_ANNO, predGUID);
|
|
|
|
if (followers.length > 1)
|
|
|
|
this._log.warn(predId + " has more than one followers: " + followers);
|
|
|
|
|
|
|
|
// Start at the first follower and move the chain of followers
|
|
|
|
let parent = Svc.Bookmark.getFolderIdForItem(predId);
|
|
|
|
followers.forEach(function(follow) {
|
|
|
|
this._log.trace("Repositioning " + follow + " behind " + predId);
|
|
|
|
if (Svc.Bookmark.getFolderIdForItem(follow) != parent) {
|
|
|
|
this._log.warn("Follower doesn't have the same parent: " + parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move the chain of followers to after the predecessor
|
|
|
|
let insertPos = Svc.Bookmark.getItemIndex(predId) + 1;
|
|
|
|
this._moveItemChain(follow, insertPos, predId);
|
|
|
|
|
|
|
|
// Remove the annotation now that we're putting it in the right spot
|
|
|
|
Svc.Annos.removeItemAnnotation(follow, PREDECESSOR_ANNO);
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2008-12-17 04:06:45 +03:00
|
|
|
create: function BStore_create(record) {
|
2008-06-03 23:38:48 +04:00
|
|
|
let newId;
|
2009-04-14 01:39:29 +04:00
|
|
|
switch (record.type) {
|
2008-06-03 23:38:48 +04:00
|
|
|
case "bookmark":
|
2009-07-14 04:43:15 +04:00
|
|
|
case "query":
|
2008-06-03 23:38:48 +04:00
|
|
|
case "microsummary": {
|
2009-04-14 01:39:29 +04:00
|
|
|
let uri = Utils.makeURI(record.bmkUri);
|
2009-08-16 23:39:15 +04:00
|
|
|
newId = this._bms.insertBookmark(record._parent, uri, record._insertPos,
|
|
|
|
record.title);
|
2009-08-16 23:39:30 +04:00
|
|
|
this._log.debug(["created bookmark", newId, "under", record._parent, "at",
|
|
|
|
record._insertPos, "as", record.title, record.bmkUri].join(" "));
|
|
|
|
|
2009-07-14 00:40:49 +04:00
|
|
|
this._tagURI(uri, record.tags);
|
2009-04-14 01:39:29 +04:00
|
|
|
this._bms.setKeywordForBookmark(newId, record.keyword);
|
2009-08-14 04:59:26 +04:00
|
|
|
if (record.description)
|
|
|
|
Utils.anno(newId, "bookmarkProperties/description", record.description);
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2009-06-17 03:16:39 +04:00
|
|
|
if (record.loadInSidebar)
|
2009-08-14 04:59:26 +04:00
|
|
|
Utils.anno(newId, "bookmarkProperties/loadInSidebar", true);
|
2009-06-17 03:16:39 +04:00
|
|
|
|
2009-04-14 01:39:29 +04:00
|
|
|
if (record.type == "microsummary") {
|
2008-06-03 23:38:48 +04:00
|
|
|
this._log.debug(" \-> is a microsummary");
|
2009-08-14 04:59:26 +04:00
|
|
|
Utils.anno(newId, "bookmarks/staticTitle", record.staticTitle || "");
|
2009-04-14 01:39:29 +04:00
|
|
|
let genURI = Utils.makeURI(record.generatorUri);
|
2008-12-30 10:28:17 +03:00
|
|
|
if (this._ms) {
|
2008-12-12 01:26:20 +03:00
|
|
|
try {
|
2008-12-29 06:59:44 +03:00
|
|
|
let micsum = this._ms.createMicrosummary(uri, genURI);
|
2008-12-12 01:26:20 +03:00
|
|
|
this._ms.setMicrosummary(newId, micsum);
|
|
|
|
}
|
|
|
|
catch(ex) { /* ignore "missing local generator" exceptions */ }
|
2008-12-30 10:28:17 +03:00
|
|
|
} else {
|
|
|
|
this._log.warn("Can't create microsummary -- not supported.");
|
2008-12-12 01:26:20 +03:00
|
|
|
}
|
2008-06-03 23:38:48 +04:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case "folder":
|
2009-08-16 23:39:15 +04:00
|
|
|
newId = this._bms.createFolder(record._parent, record.title,
|
|
|
|
record._insertPos);
|
2009-08-16 23:39:30 +04:00
|
|
|
this._log.debug(["created folder", newId, "under", record._parent, "at",
|
|
|
|
record._insertPos, "as", record.title].join(" "));
|
2010-04-02 02:11:42 +04:00
|
|
|
|
|
|
|
if (record.description)
|
|
|
|
Utils.anno(newId, "bookmarkProperties/description", record.description);
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
|
|
|
case "livemark":
|
2009-08-27 01:22:11 +04:00
|
|
|
let siteURI = null;
|
|
|
|
if (record.siteUri != null)
|
|
|
|
siteURI = Utils.makeURI(record.siteUri);
|
|
|
|
|
|
|
|
newId = this._ls.createLivemark(record._parent, record.title, siteURI,
|
|
|
|
Utils.makeURI(record.feedUri), record._insertPos);
|
2009-08-16 23:39:30 +04:00
|
|
|
this._log.debug(["created livemark", newId, "under", record._parent, "at",
|
|
|
|
record._insertPos, "as", record.title, record.siteUri, record.feedUri].
|
|
|
|
join(" "));
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
|
|
|
case "separator":
|
2009-08-16 23:39:15 +04:00
|
|
|
newId = this._bms.insertSeparator(record._parent, record._insertPos);
|
2009-08-16 23:39:30 +04:00
|
|
|
this._log.debug(["created separator", newId, "under", record._parent,
|
|
|
|
"at", record._insertPos].join(" "));
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
2009-07-10 04:15:00 +04:00
|
|
|
case "item":
|
|
|
|
this._log.debug(" -> got a generic places item.. do nothing?");
|
2009-08-15 12:04:06 +04:00
|
|
|
return;
|
2008-06-03 23:38:48 +04:00
|
|
|
default:
|
2009-04-14 01:39:29 +04:00
|
|
|
this._log.error("_create: Unknown item type: " + record.type);
|
2009-08-15 12:04:06 +04:00
|
|
|
return;
|
2008-12-05 11:39:54 +03:00
|
|
|
}
|
2009-08-15 12:04:06 +04:00
|
|
|
|
|
|
|
this._log.trace("Setting GUID of new item " + newId + " to " + record.id);
|
|
|
|
this._setGUID(newId, record.id);
|
2008-06-03 23:38:48 +04:00
|
|
|
},
|
|
|
|
|
2008-12-17 04:06:45 +03:00
|
|
|
remove: function BStore_remove(record) {
|
2009-08-15 11:59:49 +04:00
|
|
|
let itemId = idForGUID(record.id);
|
2009-01-07 00:54:18 +03:00
|
|
|
if (itemId <= 0) {
|
2008-12-19 22:48:09 +03:00
|
|
|
this._log.debug("Item " + record.id + " already removed");
|
2008-06-03 23:38:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var type = this._bms.getItemType(itemId);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case this._bms.TYPE_BOOKMARK:
|
2008-12-17 04:06:45 +03:00
|
|
|
this._log.debug(" -> removing bookmark " + record.id);
|
2009-04-08 08:17:40 +04:00
|
|
|
this._ts.untagURI(this._bms.getBookmarkURI(itemId), null);
|
2008-06-03 23:38:48 +04:00
|
|
|
this._bms.removeItem(itemId);
|
|
|
|
break;
|
|
|
|
case this._bms.TYPE_FOLDER:
|
2008-12-17 04:06:45 +03:00
|
|
|
this._log.debug(" -> removing folder " + record.id);
|
2009-11-18 21:24:09 +03:00
|
|
|
Svc.Bookmark.removeItem(itemId);
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
|
|
|
case this._bms.TYPE_SEPARATOR:
|
2008-12-17 04:06:45 +03:00
|
|
|
this._log.debug(" -> removing separator " + record.id);
|
2008-06-03 23:38:48 +04:00
|
|
|
this._bms.removeItem(itemId);
|
|
|
|
break;
|
|
|
|
default:
|
2008-12-17 04:06:45 +03:00
|
|
|
this._log.error("remove: Unknown item type: " + type);
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-17 04:06:45 +03:00
|
|
|
update: function BStore_update(record) {
|
2009-08-15 11:59:49 +04:00
|
|
|
let itemId = idForGUID(record.id);
|
2008-12-17 04:06:45 +03:00
|
|
|
|
2009-01-07 00:54:18 +03:00
|
|
|
if (itemId <= 0) {
|
2008-12-23 22:30:31 +03:00
|
|
|
this._log.debug("Skipping update for unknown item: " + record.id);
|
2008-06-03 23:38:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-23 22:30:31 +03:00
|
|
|
this._log.trace("Updating " + record.id + " (" + itemId + ")");
|
|
|
|
|
2009-08-19 05:36:31 +04:00
|
|
|
// Move the bookmark to a new parent if necessary
|
|
|
|
if (Svc.Bookmark.getFolderIdForItem(itemId) != record._parent) {
|
|
|
|
this._log.trace("Moving item to a new parent");
|
|
|
|
Svc.Bookmark.moveItem(itemId, record._parent, record._insertPos);
|
|
|
|
}
|
|
|
|
// Move the chain of bookmarks to a new position
|
|
|
|
else if (Svc.Bookmark.getItemIndex(itemId) != record._insertPos &&
|
|
|
|
!record._orphan) {
|
|
|
|
this._log.trace("Moving item and followers to a new position");
|
|
|
|
|
|
|
|
// Stop moving at the predecessor unless we don't have one
|
|
|
|
this._moveItemChain(itemId, record._insertPos, record._predId || itemId);
|
2008-12-23 22:30:31 +03:00
|
|
|
}
|
|
|
|
|
2009-04-14 01:18:11 +04:00
|
|
|
for (let [key, val] in Iterator(record.cleartext)) {
|
2008-06-03 23:38:48 +04:00
|
|
|
switch (key) {
|
|
|
|
case "title":
|
2009-04-14 01:18:11 +04:00
|
|
|
this._bms.setItemTitle(itemId, val);
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
2009-04-14 01:39:29 +04:00
|
|
|
case "bmkUri":
|
2009-04-14 01:18:11 +04:00
|
|
|
this._bms.changeBookmarkURI(itemId, Utils.makeURI(val));
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
2009-07-14 00:40:49 +04:00
|
|
|
case "tags":
|
|
|
|
this._tagURI(this._bms.getBookmarkURI(itemId), val);
|
|
|
|
break;
|
2008-06-03 23:38:48 +04:00
|
|
|
case "keyword":
|
2009-04-14 01:18:11 +04:00
|
|
|
this._bms.setKeywordForBookmark(itemId, val);
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
|
|
|
case "description":
|
2009-08-14 04:59:26 +04:00
|
|
|
Utils.anno(itemId, "bookmarkProperties/description", val);
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
2009-06-17 03:16:39 +04:00
|
|
|
case "loadInSidebar":
|
|
|
|
if (val)
|
2009-08-14 04:59:26 +04:00
|
|
|
Utils.anno(itemId, "bookmarkProperties/loadInSidebar", true);
|
2009-06-17 03:16:39 +04:00
|
|
|
else
|
2009-08-14 04:59:26 +04:00
|
|
|
Svc.Annos.removeItemAnnotation(itemId, "bookmarkProperties/loadInSidebar");
|
2009-06-17 03:16:39 +04:00
|
|
|
break;
|
2009-04-14 01:39:29 +04:00
|
|
|
case "generatorUri": {
|
2009-01-22 06:04:13 +03:00
|
|
|
try {
|
2009-04-14 01:39:29 +04:00
|
|
|
let micsumURI = this._bms.getBookmarkURI(itemId);
|
2009-04-14 01:18:11 +04:00
|
|
|
let genURI = Utils.makeURI(val);
|
2009-01-22 06:04:13 +03:00
|
|
|
if (this._ms == SERVICE_NOT_SUPPORTED) {
|
|
|
|
this._log.warn("Can't create microsummary -- not supported.");
|
|
|
|
} else {
|
|
|
|
let micsum = this._ms.createMicrosummary(micsumURI, genURI);
|
|
|
|
this._ms.setMicrosummary(itemId, micsum);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this._log.debug("Could not set microsummary generator URI: " + e);
|
|
|
|
}
|
2008-06-03 23:38:48 +04:00
|
|
|
} break;
|
2009-04-14 01:39:29 +04:00
|
|
|
case "siteUri":
|
2009-04-14 01:18:11 +04:00
|
|
|
this._ls.setSiteURI(itemId, Utils.makeURI(val));
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
2009-04-14 01:39:29 +04:00
|
|
|
case "feedUri":
|
2009-04-14 01:18:11 +04:00
|
|
|
this._ls.setFeedURI(itemId, Utils.makeURI(val));
|
2008-06-03 23:38:48 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-09 00:21:25 +03:00
|
|
|
changeItemID: function BStore_changeItemID(oldID, newID) {
|
2010-03-06 01:43:11 +03:00
|
|
|
// Remember the GUID change for incoming records
|
2009-09-09 10:33:15 +04:00
|
|
|
this.aliases[oldID] = newID;
|
|
|
|
|
|
|
|
// Update any existing annotation references
|
|
|
|
this._findAnnoItems(PARENT_ANNO, oldID).forEach(function(itemId) {
|
|
|
|
Utils.anno(itemId, PARENT_ANNO, "T" + newID);
|
|
|
|
}, this);
|
|
|
|
this._findAnnoItems(PREDECESSOR_ANNO, oldID).forEach(function(itemId) {
|
|
|
|
Utils.anno(itemId, PREDECESSOR_ANNO, "R" + newID);
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
// Make sure there's an item to change GUIDs
|
2009-08-15 11:59:49 +04:00
|
|
|
let itemId = idForGUID(oldID);
|
2009-09-09 10:33:15 +04:00
|
|
|
if (itemId <= 0)
|
2008-12-05 11:39:54 +03:00
|
|
|
return;
|
2008-11-26 18:25:28 +03:00
|
|
|
|
|
|
|
this._log.debug("Changing GUID " + oldID + " to " + newID);
|
2009-08-15 12:04:06 +04:00
|
|
|
this._setGUID(itemId, newID);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setGUID: function BStore__setGUID(itemId, guid) {
|
|
|
|
let collision = idForGUID(guid);
|
|
|
|
if (collision != -1) {
|
|
|
|
this._log.warn("Freeing up GUID " + guid + " used by " + collision);
|
|
|
|
Svc.Annos.removeItemAnnotation(collision, "placesInternal/GUID");
|
|
|
|
}
|
|
|
|
Svc.Bookmark.setItemGUID(itemId, guid);
|
2008-11-26 18:25:28 +03:00
|
|
|
},
|
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
_getNode: function BStore__getNode(folder) {
|
2008-06-03 23:38:48 +04:00
|
|
|
let query = this._hsvc.getNewQuery();
|
|
|
|
query.setFolders([folder], 1);
|
|
|
|
return this._hsvc.executeQuery(query, this._hsvc.getNewQueryOptions()).root;
|
|
|
|
},
|
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
_getTags: function BStore__getTags(uri) {
|
|
|
|
try {
|
|
|
|
if (typeof(uri) == "string")
|
|
|
|
uri = Utils.makeURI(uri);
|
|
|
|
} catch(e) {
|
|
|
|
this._log.warn("Could not parse URI \"" + uri + "\": " + e);
|
2008-06-03 23:38:48 +04:00
|
|
|
}
|
2008-12-29 06:59:44 +03:00
|
|
|
return this._ts.getTagsForURI(uri, {});
|
|
|
|
},
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
_getDescription: function BStore__getDescription(id) {
|
|
|
|
try {
|
2009-08-14 04:59:26 +04:00
|
|
|
return Utils.anno(id, "bookmarkProperties/description");
|
2008-12-29 06:59:44 +03:00
|
|
|
} catch (e) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-06-17 03:16:39 +04:00
|
|
|
_isLoadInSidebar: function BStore__isLoadInSidebar(id) {
|
2009-08-14 04:59:26 +04:00
|
|
|
return Svc.Annos.itemHasAnnotation(id, "bookmarkProperties/loadInSidebar");
|
2009-06-17 03:16:39 +04:00
|
|
|
},
|
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
_getStaticTitle: function BStore__getStaticTitle(id) {
|
|
|
|
try {
|
2009-08-14 04:59:26 +04:00
|
|
|
return Utils.anno(id, "bookmarks/staticTitle");
|
2008-12-29 06:59:44 +03:00
|
|
|
} catch (e) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Create a record starting from the weave id (places guid)
|
2010-03-06 01:46:48 +03:00
|
|
|
createRecord: function createRecord(guid) {
|
2009-08-15 11:59:49 +04:00
|
|
|
let placeId = idForGUID(guid);
|
2010-03-25 23:58:27 +03:00
|
|
|
let record;
|
2009-01-07 00:54:18 +03:00
|
|
|
if (placeId <= 0) { // deleted item
|
2008-12-29 06:59:44 +03:00
|
|
|
record = new PlacesItem();
|
2009-04-03 21:38:47 +04:00
|
|
|
record.deleted = true;
|
2008-12-29 06:59:44 +03:00
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
2009-11-20 08:34:17 +03:00
|
|
|
let parent = Svc.Bookmark.getFolderIdForItem(placeId);
|
2008-12-29 06:59:44 +03:00
|
|
|
switch (this._bms.getItemType(placeId)) {
|
|
|
|
case this._bms.TYPE_BOOKMARK:
|
2009-07-14 04:43:15 +04:00
|
|
|
let bmkUri = this._bms.getBookmarkURI(placeId).spec;
|
2008-12-29 06:59:44 +03:00
|
|
|
if (this._ms && this._ms.hasMicrosummary(placeId)) {
|
|
|
|
record = new BookmarkMicsum();
|
|
|
|
let micsum = this._ms.getMicrosummary(placeId);
|
2009-04-14 01:39:29 +04:00
|
|
|
record.generatorUri = micsum.generator.uri.spec; // breaks local generators
|
2008-12-29 06:59:44 +03:00
|
|
|
record.staticTitle = this._getStaticTitle(placeId);
|
2009-07-14 04:43:15 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (bmkUri.search(/^place:/) == 0) {
|
|
|
|
record = new BookmarkQuery();
|
2008-06-25 05:09:41 +04:00
|
|
|
|
2009-07-14 04:43:15 +04:00
|
|
|
// Get the actual tag name instead of the local itemId
|
|
|
|
let folder = bmkUri.match(/[:&]folder=(\d+)/);
|
|
|
|
try {
|
|
|
|
// There might not be the tag yet when creating on a new client
|
|
|
|
if (folder != null) {
|
|
|
|
folder = folder[1];
|
|
|
|
record.folderName = this._bms.getItemTitle(folder);
|
|
|
|
this._log.debug("query id: " + folder + " = " + record.folderName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
record = new Bookmark();
|
2008-12-29 06:59:44 +03:00
|
|
|
record.title = this._bms.getItemTitle(placeId);
|
2008-06-03 23:38:48 +04:00
|
|
|
}
|
|
|
|
|
2010-01-25 20:33:49 +03:00
|
|
|
record.parentName = Svc.Bookmark.getItemTitle(parent);
|
2009-07-14 04:43:15 +04:00
|
|
|
record.bmkUri = bmkUri;
|
2008-12-29 06:59:44 +03:00
|
|
|
record.tags = this._getTags(record.bmkUri);
|
|
|
|
record.keyword = this._bms.getKeywordForBookmark(placeId);
|
|
|
|
record.description = this._getDescription(placeId);
|
2009-06-17 03:16:39 +04:00
|
|
|
record.loadInSidebar = this._isLoadInSidebar(placeId);
|
2008-12-29 06:59:44 +03:00
|
|
|
break;
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
case this._bms.TYPE_FOLDER:
|
|
|
|
if (this._ls.isLivemark(placeId)) {
|
|
|
|
record = new Livemark();
|
2009-08-27 01:22:11 +04:00
|
|
|
|
|
|
|
let siteURI = this._ls.getSiteURI(placeId);
|
|
|
|
if (siteURI != null)
|
|
|
|
record.siteUri = siteURI.spec;
|
2009-04-14 01:39:29 +04:00
|
|
|
record.feedUri = this._ls.getFeedURI(placeId).spec;
|
2008-06-05 00:40:53 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
} else {
|
|
|
|
record = new BookmarkFolder();
|
2008-06-05 00:40:53 +04:00
|
|
|
}
|
2009-04-02 02:12:08 +04:00
|
|
|
|
2009-11-20 08:34:17 +03:00
|
|
|
record.parentName = Svc.Bookmark.getItemTitle(parent);
|
2009-04-02 02:12:08 +04:00
|
|
|
record.title = this._bms.getItemTitle(placeId);
|
2010-04-02 02:11:42 +04:00
|
|
|
record.description = this._getDescription(placeId);
|
2008-12-29 06:59:44 +03:00
|
|
|
break;
|
2008-06-05 00:40:53 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
case this._bms.TYPE_SEPARATOR:
|
|
|
|
record = new BookmarkSeparator();
|
2009-09-09 10:33:58 +04:00
|
|
|
// Create a positioning identifier for the separator
|
2009-11-20 08:34:17 +03:00
|
|
|
record.parentName = Svc.Bookmark.getItemTitle(parent);
|
|
|
|
record.pos = Svc.Bookmark.getItemIndex(placeId);
|
2008-12-29 06:59:44 +03:00
|
|
|
break;
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
case this._bms.TYPE_DYNAMIC_CONTAINER:
|
|
|
|
record = new PlacesItem();
|
|
|
|
this._log.warn("Don't know how to serialize dynamic containers yet");
|
|
|
|
break;
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
default:
|
|
|
|
record = new PlacesItem();
|
|
|
|
this._log.warn("Unknown item type, cannot serialize: " +
|
|
|
|
this._bms.getItemType(placeId));
|
2008-06-03 23:38:48 +04:00
|
|
|
}
|
|
|
|
|
2009-08-16 23:39:00 +04:00
|
|
|
record.parentid = this._getParentGUIDForId(placeId);
|
|
|
|
record.predecessorid = this._getPredecessorGUIDForId(placeId);
|
2009-10-17 03:19:28 +04:00
|
|
|
record.sortindex = this._calculateIndex(record);
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
return record;
|
2008-06-03 23:38:48 +04:00
|
|
|
},
|
|
|
|
|
2009-10-17 03:19:28 +04:00
|
|
|
get _frecencyStm() {
|
|
|
|
this._log.trace("Creating SQL statement: _frecencyStm");
|
|
|
|
let stm = Svc.History.DBConnection.createStatement(
|
|
|
|
"SELECT frecency " +
|
|
|
|
"FROM moz_places_view " +
|
|
|
|
"WHERE url = :url");
|
|
|
|
this.__defineGetter__("_frecencyStm", function() stm);
|
|
|
|
return stm;
|
|
|
|
},
|
|
|
|
|
|
|
|
_calculateIndex: function _calculateIndex(record) {
|
|
|
|
// For anything directly under the toolbar, give it a boost of more than an
|
|
|
|
// unvisited bookmark
|
|
|
|
let index = 0;
|
|
|
|
if (record.parentid == "toolbar")
|
|
|
|
index += 150;
|
|
|
|
|
|
|
|
// Add in the bookmark's frecency if we have something
|
|
|
|
if (record.bmkUri != null) {
|
|
|
|
try {
|
|
|
|
this._frecencyStm.params.url = record.bmkUri;
|
|
|
|
if (this._frecencyStm.step())
|
|
|
|
index += this._frecencyStm.row.frecency;
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
this._frecencyStm.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
2009-08-16 23:39:00 +04:00
|
|
|
_getParentGUIDForId: function BStore__getParentGUIDForId(itemId) {
|
2009-08-25 03:17:59 +04:00
|
|
|
// Give the parent annotation if it exists
|
|
|
|
try {
|
|
|
|
// XXX Work around Bug 510628 by removing prepended parenT
|
|
|
|
return Utils.anno(itemId, PARENT_ANNO).slice(1);
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
|
2009-01-09 08:33:59 +03:00
|
|
|
let parentid = this._bms.getFolderIdForItem(itemId);
|
|
|
|
if (parentid == -1) {
|
|
|
|
this._log.debug("Found orphan bookmark, reparenting to unfiled");
|
|
|
|
parentid = this._bms.unfiledBookmarksFolder;
|
|
|
|
this._bms.moveItem(itemId, parentid, -1);
|
|
|
|
}
|
2009-08-15 11:59:49 +04:00
|
|
|
return GUIDForId(parentid);
|
2009-01-03 00:49:19 +03:00
|
|
|
},
|
|
|
|
|
2009-08-16 23:39:00 +04:00
|
|
|
_getPredecessorGUIDForId: function BStore__getPredecessorGUIDForId(itemId) {
|
2009-08-25 03:17:59 +04:00
|
|
|
// Give the predecessor annotation if it exists
|
|
|
|
try {
|
|
|
|
// XXX Work around Bug 510628 by removing prepended predecessoR
|
|
|
|
return Utils.anno(itemId, PREDECESSOR_ANNO).slice(1);
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
|
2009-08-16 23:39:00 +04:00
|
|
|
// Figure out the predecessor, unless it's the first item
|
|
|
|
let itemPos = Svc.Bookmark.getItemIndex(itemId);
|
|
|
|
if (itemPos == 0)
|
|
|
|
return;
|
|
|
|
|
2009-10-14 03:27:10 +04:00
|
|
|
// For items directly under unfiled/unsorted, give no predecessor
|
2009-08-16 23:39:00 +04:00
|
|
|
let parentId = Svc.Bookmark.getFolderIdForItem(itemId);
|
2009-10-14 03:27:10 +04:00
|
|
|
if (parentId == Svc.Bookmark.unfiledBookmarksFolder)
|
|
|
|
return;
|
2009-08-20 06:32:05 +04:00
|
|
|
|
2009-10-14 03:27:10 +04:00
|
|
|
let predecessorId = Svc.Bookmark.getIdForItemAt(parentId, itemPos - 1);
|
2009-08-20 06:32:05 +04:00
|
|
|
if (predecessorId == -1) {
|
|
|
|
this._log.debug("No predecessor directly before " + itemId + " under " +
|
|
|
|
parentId + " at " + itemPos);
|
|
|
|
|
|
|
|
// Find the predecessor before the item
|
|
|
|
do {
|
|
|
|
// No more items to check, it must be the first one
|
|
|
|
if (--itemPos < 0)
|
|
|
|
break;
|
|
|
|
predecessorId = Svc.Bookmark.getIdForItemAt(parentId, itemPos);
|
|
|
|
} while (predecessorId == -1);
|
|
|
|
|
|
|
|
// Fix up the item to be at the right position for next time
|
|
|
|
itemPos++;
|
|
|
|
this._log.debug("Fixing " + itemId + " to be at position " + itemPos);
|
|
|
|
Svc.Bookmark.moveItem(itemId, parentId, itemPos);
|
|
|
|
|
|
|
|
// There must be no predecessor for this item!
|
|
|
|
if (itemPos == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-16 23:39:00 +04:00
|
|
|
return GUIDForId(predecessorId);
|
|
|
|
},
|
|
|
|
|
2009-08-14 05:50:54 +04:00
|
|
|
_getChildren: function BStore_getChildren(guid, items) {
|
2009-01-03 08:13:32 +03:00
|
|
|
let node = guid; // the recursion case
|
|
|
|
if (typeof(node) == "string") // callers will give us the guid as the first arg
|
2009-08-15 11:59:49 +04:00
|
|
|
node = this._getNode(idForGUID(guid));
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
if (node.type == node.RESULT_TYPE_FOLDER &&
|
|
|
|
!this._ls.isLivemark(node.itemId)) {
|
|
|
|
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
node.containerOpen = true;
|
2009-08-14 05:50:54 +04:00
|
|
|
|
|
|
|
// Remember all the children GUIDs and recursively get more
|
2008-12-29 06:59:44 +03:00
|
|
|
for (var i = 0; i < node.childCount; i++) {
|
|
|
|
let child = node.getChild(i);
|
2009-08-15 11:59:49 +04:00
|
|
|
items[GUIDForId(child.itemId)] = true;
|
2009-08-14 05:50:54 +04:00
|
|
|
this._getChildren(child, items);
|
2008-12-29 06:59:44 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-08 20:53:32 +03:00
|
|
|
|
2008-12-29 06:59:44 +03:00
|
|
|
return items;
|
2008-12-08 20:53:32 +03:00
|
|
|
},
|
|
|
|
|
2009-07-14 00:40:49 +04:00
|
|
|
_tagURI: function BStore_tagURI(bmkURI, tags) {
|
|
|
|
// Filter out any null/undefined/empty tags
|
|
|
|
tags = tags.filter(function(t) t);
|
|
|
|
|
|
|
|
// Temporarily tag a dummy uri to preserve tag ids when untagging
|
2009-07-14 04:43:15 +04:00
|
|
|
let dummyURI = Utils.makeURI("about:weave#BStore_tagURI");
|
2009-07-14 00:40:49 +04:00
|
|
|
this._ts.tagURI(dummyURI, tags);
|
|
|
|
this._ts.untagURI(bmkURI, null);
|
|
|
|
this._ts.tagURI(bmkURI, tags);
|
|
|
|
this._ts.untagURI(dummyURI, null);
|
|
|
|
},
|
2009-01-03 08:13:32 +03:00
|
|
|
|
|
|
|
getAllIDs: function BStore_getAllIDs() {
|
|
|
|
let items = {};
|
2009-08-15 11:59:49 +04:00
|
|
|
for (let [guid, id] in Iterator(kSpecialIds))
|
|
|
|
if (guid != "places" && guid != "tags")
|
|
|
|
this._getChildren(guid, items);
|
2009-01-03 00:49:19 +03:00
|
|
|
return items;
|
|
|
|
},
|
|
|
|
|
2008-06-03 23:38:48 +04:00
|
|
|
wipe: function BStore_wipe() {
|
2009-11-26 04:09:32 +03:00
|
|
|
// some nightly builds of 3.7 don't have this function
|
|
|
|
try {
|
|
|
|
PlacesUtils.archiveBookmarksFile(null, true);
|
|
|
|
} catch(e) {}
|
|
|
|
|
2009-08-15 11:59:49 +04:00
|
|
|
for (let [guid, id] in Iterator(kSpecialIds))
|
|
|
|
if (guid != "places")
|
2009-04-08 08:17:40 +04:00
|
|
|
this._bms.removeFolderChildren(id);
|
2008-06-03 23:38:48 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-02-12 02:29:15 +03:00
|
|
|
function BookmarksTracker(name) {
|
|
|
|
Tracker.call(this, name);
|
2010-02-12 02:25:31 +03:00
|
|
|
|
|
|
|
// Ignore changes to the special roots
|
|
|
|
for (let guid in kSpecialIds)
|
|
|
|
this.ignoreID(guid);
|
|
|
|
|
|
|
|
Svc.Bookmark.addObserver(this, false);
|
2008-06-03 23:38:48 +04:00
|
|
|
}
|
|
|
|
BookmarksTracker.prototype = {
|
2008-11-07 06:18:46 +03:00
|
|
|
__proto__: Tracker.prototype,
|
2008-12-05 11:39:54 +03:00
|
|
|
|
|
|
|
get _bms() {
|
|
|
|
let bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
|
|
|
this.__defineGetter__("_bms", function() bms);
|
|
|
|
return bms;
|
|
|
|
},
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2009-01-16 00:58:59 +03:00
|
|
|
get _ls() {
|
|
|
|
let ls = Cc["@mozilla.org/browser/livemark-service;2"].
|
|
|
|
getService(Ci.nsILivemarkService);
|
|
|
|
this.__defineGetter__("_ls", function() ls);
|
|
|
|
return ls;
|
|
|
|
},
|
|
|
|
|
2009-06-17 19:51:54 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsINavBookmarkObserver,
|
2009-06-17 19:51:54 +04:00
|
|
|
Ci.nsINavBookmarkObserver_MOZILLA_1_9_1_ADDITIONS
|
2009-06-17 19:51:54 +04:00
|
|
|
]),
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2009-06-17 19:51:54 +04:00
|
|
|
/**
|
|
|
|
* Add a bookmark (places) id to be uploaded and bump up the sync score
|
|
|
|
*
|
|
|
|
* @param itemId
|
|
|
|
* Places internal id of the bookmark to upload
|
|
|
|
*/
|
|
|
|
_addId: function BMT__addId(itemId) {
|
2009-08-15 11:59:49 +04:00
|
|
|
if (this.addChangedID(GUIDForId(itemId)))
|
2009-06-17 19:51:54 +04:00
|
|
|
this._upScore();
|
|
|
|
},
|
|
|
|
|
2009-08-19 05:39:10 +04:00
|
|
|
/**
|
|
|
|
* Add the successor id for the item that follows the given item
|
|
|
|
*/
|
|
|
|
_addSuccessor: function BMT__addSuccessor(itemId) {
|
|
|
|
let parentId = Svc.Bookmark.getFolderIdForItem(itemId);
|
|
|
|
let itemPos = Svc.Bookmark.getItemIndex(itemId);
|
|
|
|
let succId = Svc.Bookmark.getIdForItemAt(parentId, itemPos + 1);
|
|
|
|
if (succId != -1)
|
|
|
|
this._addId(succId);
|
|
|
|
},
|
|
|
|
|
2008-11-20 03:21:12 +03:00
|
|
|
/* Every add/remove/change is worth 10 points */
|
2008-12-06 11:12:40 +03:00
|
|
|
_upScore: function BMT__upScore() {
|
2009-11-09 20:57:58 +03:00
|
|
|
this.score += 10;
|
2008-06-03 23:38:48 +04:00
|
|
|
},
|
2008-11-20 03:21:12 +03:00
|
|
|
|
2009-04-08 07:56:04 +04:00
|
|
|
/**
|
|
|
|
* Determine if a change should be ignored: we're ignoring everything or the
|
|
|
|
* folder is for livemarks
|
|
|
|
*
|
2009-06-17 19:51:54 +04:00
|
|
|
* @param itemId
|
|
|
|
* Item under consideration to ignore
|
|
|
|
* @param folder (optional)
|
2009-04-08 07:56:04 +04:00
|
|
|
* Folder of the item being changed
|
|
|
|
*/
|
2009-06-17 19:51:54 +04:00
|
|
|
_ignore: function BMT__ignore(itemId, folder) {
|
2009-04-08 07:56:04 +04:00
|
|
|
// Ignore unconditionally if the engine tells us to
|
|
|
|
if (this.ignoreAll)
|
|
|
|
return true;
|
|
|
|
|
2009-12-11 03:12:14 +03:00
|
|
|
// Ensure that the mobile bookmarks query is correct in the UI
|
|
|
|
this._ensureMobileQuery();
|
|
|
|
|
|
|
|
// Make sure to remove items that have the exclude annotation
|
|
|
|
if (Svc.Annos.itemHasAnnotation(itemId, "places/excludeFromBackup")) {
|
|
|
|
this.removeChangedID(GUIDForId(itemId));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-17 19:51:54 +04:00
|
|
|
// Get the folder id if we weren't given one
|
|
|
|
if (folder == null)
|
|
|
|
folder = this._bms.getFolderIdForItem(itemId);
|
|
|
|
|
2009-08-15 11:59:49 +04:00
|
|
|
let tags = kSpecialIds.tags;
|
2009-04-08 08:17:40 +04:00
|
|
|
// Ignore changes to tags (folders under the tags folder)
|
|
|
|
if (folder == tags)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Ignore tag items (the actual instance of a tag for a bookmark)
|
|
|
|
if (this._bms.getFolderIdForItem(folder) == tags)
|
|
|
|
return true;
|
|
|
|
|
2009-04-08 07:56:04 +04:00
|
|
|
// Ignore livemark children
|
|
|
|
return this._ls.isLivemark(folder);
|
|
|
|
},
|
|
|
|
|
2008-12-06 11:12:40 +03:00
|
|
|
onItemAdded: function BMT_onEndUpdateBatch(itemId, folder, index) {
|
2009-06-17 19:51:54 +04:00
|
|
|
if (this._ignore(itemId, folder))
|
2009-01-16 00:58:59 +03:00
|
|
|
return;
|
2009-02-02 22:43:06 +03:00
|
|
|
|
2008-12-19 22:48:09 +03:00
|
|
|
this._log.trace("onItemAdded: " + itemId);
|
2009-06-17 19:51:54 +04:00
|
|
|
this._addId(itemId);
|
2009-08-19 05:39:10 +04:00
|
|
|
this._addSuccessor(itemId);
|
2008-12-06 11:12:40 +03:00
|
|
|
},
|
|
|
|
|
2009-06-17 19:51:54 +04:00
|
|
|
onBeforeItemRemoved: function BMT_onBeforeItemRemoved(itemId) {
|
2009-06-17 19:51:54 +04:00
|
|
|
if (this._ignore(itemId))
|
2009-01-16 00:58:59 +03:00
|
|
|
return;
|
2009-02-02 22:43:06 +03:00
|
|
|
|
2009-06-17 19:51:54 +04:00
|
|
|
this._log.trace("onBeforeItemRemoved: " + itemId);
|
|
|
|
this._addId(itemId);
|
2009-08-19 05:39:10 +04:00
|
|
|
this._addSuccessor(itemId);
|
2008-06-03 23:38:48 +04:00
|
|
|
},
|
2008-11-20 03:21:12 +03:00
|
|
|
|
2009-12-11 03:12:14 +03:00
|
|
|
_ensureMobileQuery: function _ensureMobileQuery() {
|
|
|
|
let anno = "PlacesOrganizer/OrganizerQuery";
|
|
|
|
let find = function(val) Svc.Annos.getItemsWithAnnotation(anno, {}).filter(
|
|
|
|
function(id) Utils.anno(id, anno) == val);
|
2009-02-02 22:43:06 +03:00
|
|
|
|
2009-12-11 03:12:14 +03:00
|
|
|
// Don't continue if the Library isn't ready
|
|
|
|
let all = find("AllBookmarks");
|
|
|
|
if (all.length == 0)
|
2009-08-26 03:15:05 +04:00
|
|
|
return;
|
2009-12-11 03:12:14 +03:00
|
|
|
|
|
|
|
// Disable handling of notifications while changing the mobile query
|
|
|
|
this.ignoreAll = true;
|
|
|
|
|
|
|
|
let mobile = find("MobileBookmarks");
|
|
|
|
let queryURI = Utils.makeURI("place:folder=" + kSpecialIds.mobile);
|
|
|
|
let title = Str.sync.get("mobile.label");
|
2009-12-16 01:21:13 +03:00
|
|
|
|
|
|
|
// Don't add OR do remove the mobile bookmarks if there's nothing
|
|
|
|
if (Svc.Bookmark.getIdForItemAt(kSpecialIds.mobile, 0) == -1) {
|
|
|
|
if (mobile.length != 0)
|
|
|
|
Svc.Bookmark.removeItem(mobile[0]);
|
|
|
|
}
|
|
|
|
// Add the mobile bookmarks query if it doesn't exist
|
|
|
|
else if (mobile.length == 0) {
|
2009-12-11 03:12:14 +03:00
|
|
|
let query = Svc.Bookmark.insertBookmark(all[0], queryURI, -1, title);
|
|
|
|
Utils.anno(query, anno, "MobileBookmarks");
|
|
|
|
Utils.anno(query, "places/excludeFromBackup", 1);
|
2009-08-26 03:15:05 +04:00
|
|
|
}
|
2009-12-11 03:12:14 +03:00
|
|
|
// Make sure the existing title is correct
|
|
|
|
else if (Svc.Bookmark.getItemTitle(mobile[0]) != title)
|
|
|
|
Svc.Bookmark.setItemTitle(mobile[0], title);
|
|
|
|
|
|
|
|
this.ignoreAll = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
onItemChanged: function BMT_onItemChanged(itemId, property, isAnno, value) {
|
|
|
|
if (this._ignore(itemId))
|
|
|
|
return;
|
2009-08-26 03:15:05 +04:00
|
|
|
|
2009-02-02 22:43:06 +03:00
|
|
|
// ignore annotations except for the ones that we sync
|
2009-06-17 03:16:39 +04:00
|
|
|
let annos = ["bookmarkProperties/description",
|
|
|
|
"bookmarkProperties/loadInSidebar", "bookmarks/staticTitle",
|
|
|
|
"livemark/feedURI", "livemark/siteURI", "microsummary/generatorURI"];
|
|
|
|
if (isAnno && annos.indexOf(property) == -1)
|
|
|
|
return;
|
2009-02-02 22:43:06 +03:00
|
|
|
|
2010-01-19 22:24:00 +03:00
|
|
|
// Ignore favicon changes to avoid unnecessary churn
|
|
|
|
if (property == "favicon")
|
|
|
|
return;
|
|
|
|
|
2009-01-14 02:55:35 +03:00
|
|
|
this._log.trace("onItemChanged: " + itemId +
|
2009-01-14 03:55:51 +03:00
|
|
|
(", " + property + (isAnno? " (anno)" : "")) +
|
|
|
|
(value? (" = \"" + value + "\"") : ""));
|
2009-06-17 19:51:54 +04:00
|
|
|
this._addId(itemId);
|
2008-06-03 23:38:48 +04:00
|
|
|
},
|
|
|
|
|
2008-12-03 03:46:24 +03:00
|
|
|
onItemMoved: function BMT_onItemMoved(itemId, oldParent, oldIndex, newParent, newIndex) {
|
2009-06-17 19:51:54 +04:00
|
|
|
if (this._ignore(itemId))
|
2009-02-02 22:43:06 +03:00
|
|
|
return;
|
|
|
|
|
2008-12-06 11:12:40 +03:00
|
|
|
this._log.trace("onItemMoved: " + itemId);
|
2009-06-17 19:51:54 +04:00
|
|
|
this._addId(itemId);
|
2009-08-19 05:39:10 +04:00
|
|
|
this._addSuccessor(itemId);
|
|
|
|
|
|
|
|
// Get the thing that's now at the old place
|
|
|
|
let oldSucc = Svc.Bookmark.getIdForItemAt(oldParent, oldIndex);
|
|
|
|
if (oldSucc != -1)
|
|
|
|
this._addId(oldSucc);
|
2010-02-04 02:34:42 +03:00
|
|
|
|
|
|
|
// Remove any position annotations now that the user moved the item
|
|
|
|
Svc.Annos.removeItemAnnotation(itemId, PARENT_ANNO);
|
|
|
|
Svc.Annos.removeItemAnnotation(itemId, PREDECESSOR_ANNO);
|
2008-11-20 03:21:12 +03:00
|
|
|
},
|
2008-06-03 23:38:48 +04:00
|
|
|
|
2008-11-20 03:21:12 +03:00
|
|
|
onBeginUpdateBatch: function BMT_onBeginUpdateBatch() {},
|
|
|
|
onEndUpdateBatch: function BMT_onEndUpdateBatch() {},
|
2009-06-17 19:51:54 +04:00
|
|
|
onItemRemoved: function BMT_onItemRemoved(itemId, folder, index) {},
|
2008-12-03 03:46:24 +03:00
|
|
|
onItemVisited: function BMT_onItemVisited(itemId, aVisitID, time) {}
|
2008-11-07 06:18:46 +03:00
|
|
|
};
|