2008-06-06 19:28:01 -07: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-04 17:23:23 -07:00
|
|
|
* Anant Narayanan <anant@kix.in>
|
2010-12-06 15:51:38 -08:00
|
|
|
* Philipp von Weitershausen <philipp@weitershausen.de>
|
2008-06-06 19:28:01 -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 ***** */
|
|
|
|
|
2008-06-30 18:50:06 -07:00
|
|
|
const EXPORTED_SYMBOLS = ['BookmarksEngine', 'BookmarksSharingManager'];
|
2008-06-03 12:38:48 -07:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2010-12-06 15:51:38 -08:00
|
|
|
const GUID_ANNO = "sync/guid";
|
2010-12-06 15:51:48 -08:00
|
|
|
const PARENT_ANNO = "sync/parent";
|
2010-12-06 15:51:56 -08:00
|
|
|
const CHILDREN_ANNO = "sync/children";
|
2008-12-11 14:26:20 -08:00
|
|
|
const SERVICE_NOT_SUPPORTED = "Service not supported on this platform";
|
2010-11-09 13:53:50 -08:00
|
|
|
const FOLDER_SORTINDEX = 1000000;
|
2008-12-11 14:26:20 -08:00
|
|
|
|
2010-05-04 12:14:48 -07:00
|
|
|
try {
|
|
|
|
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
Cu.import("resource://gre/modules/utils.js");
|
|
|
|
}
|
2008-06-29 11:44:27 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-06-16 14:30:08 -07:00
|
|
|
Cu.import("resource://services-sync/engines.js");
|
|
|
|
Cu.import("resource://services-sync/stores.js");
|
|
|
|
Cu.import("resource://services-sync/trackers.js");
|
|
|
|
Cu.import("resource://services-sync/type_records/bookmark.js");
|
|
|
|
Cu.import("resource://services-sync/util.js");
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2010-04-21 11:10:32 -07:00
|
|
|
function archiveBookmarks() {
|
|
|
|
// Some nightly builds of 3.7 don't have this function
|
|
|
|
try {
|
|
|
|
PlacesUtils.archiveBookmarksFile(null, true);
|
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
}
|
|
|
|
|
2009-06-17 09:28:15 -07:00
|
|
|
// Lazily initialize the special top level folders
|
|
|
|
let kSpecialIds = {};
|
|
|
|
[["menu", "bookmarksMenuFolder"],
|
|
|
|
["places", "placesRoot"],
|
|
|
|
["tags", "tagsFolder"],
|
|
|
|
["toolbar", "toolbarFolder"],
|
|
|
|
["unfiled", "unfiledBookmarksFolder"],
|
2009-08-15 00:59:49 -07:00
|
|
|
].forEach(function([guid, placeName]) {
|
|
|
|
Utils.lazy2(kSpecialIds, guid, function() Svc.Bookmark[placeName]);
|
2009-06-17 09:28:15 -07:00
|
|
|
});
|
2009-12-10 16:12:14 -08: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 09:28:15 -07:00
|
|
|
|
2008-12-09 12:26:14 -08:00
|
|
|
function BookmarksEngine() {
|
2010-02-11 15:29:15 -08:00
|
|
|
SyncEngine.call(this, "Bookmarks");
|
2010-02-11 15:25:31 -08:00
|
|
|
this._handleImport();
|
2008-06-24 21:15:14 -07:00
|
|
|
}
|
|
|
|
BookmarksEngine.prototype = {
|
2008-12-05 00:39:54 -08:00
|
|
|
__proto__: SyncEngine.prototype,
|
2009-04-13 12:54:31 -07:00
|
|
|
_recordObj: PlacesItem,
|
2009-01-06 13:54:18 -08:00
|
|
|
_storeObj: BookmarksStore,
|
2009-07-30 11:52:26 -07:00
|
|
|
_trackerObj: BookmarksTracker,
|
2010-12-06 15:51:38 -08:00
|
|
|
version: 2,
|
2009-07-30 11:52:26 -07:00
|
|
|
|
2009-12-02 19:20:44 -08:00
|
|
|
_handleImport: function _handleImport() {
|
2010-08-06 08:30:58 -07:00
|
|
|
Svc.Obs.add("bookmarks-restore-begin", function() {
|
2009-12-02 19:20:44 -08:00
|
|
|
this._log.debug("Ignoring changes from importing bookmarks");
|
|
|
|
this._tracker.ignoreAll = true;
|
|
|
|
}, this);
|
|
|
|
|
2010-08-06 08:30:58 -07:00
|
|
|
Svc.Obs.add("bookmarks-restore-success", function() {
|
2010-04-06 11:59:50 -07:00
|
|
|
this._log.debug("Tracking all items on successful import");
|
2009-12-02 19:20:44 -08:00
|
|
|
this._tracker.ignoreAll = false;
|
2010-04-06 11:59:50 -07:00
|
|
|
|
|
|
|
// Mark all the items as changed so they get uploaded
|
|
|
|
for (let id in this._store.getAllIDs())
|
|
|
|
this._tracker.addChangedID(id);
|
2009-12-02 19:20:44 -08:00
|
|
|
}, this);
|
|
|
|
|
2010-08-06 08:30:58 -07:00
|
|
|
Svc.Obs.add("bookmarks-restore-failed", function() {
|
2009-12-02 19:20:44 -08:00
|
|
|
this._tracker.ignoreAll = false;
|
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2009-08-31 18:04:40 -07:00
|
|
|
_sync: Utils.batchSync("Bookmark", SyncEngine),
|
2009-08-31 17:27:30 -07:00
|
|
|
|
2009-08-31 17:54:21 -07:00
|
|
|
_syncStartup: function _syncStart() {
|
|
|
|
SyncEngine.prototype._syncStartup.call(this);
|
|
|
|
|
2010-04-21 11:10:32 -07:00
|
|
|
// For first-syncs, make a backup for the user to restore
|
|
|
|
if (this.lastSync == 0)
|
|
|
|
archiveBookmarks();
|
|
|
|
|
2009-09-08 23:33:58 -07:00
|
|
|
// Lazily create a mapping of folder titles and separator positions to GUID
|
2009-11-19 21:34:17 -08:00
|
|
|
this.__defineGetter__("_lazyMap", function() {
|
|
|
|
delete this._lazyMap;
|
2009-08-31 17:54:21 -07:00
|
|
|
|
2009-11-19 21:34:17 -08:00
|
|
|
let lazyMap = {};
|
2009-08-31 17:54:21 -07:00
|
|
|
for (let guid in this._store.getAllIDs()) {
|
2009-11-19 21:34:17 -08:00
|
|
|
// Figure out what key to store the mapping
|
|
|
|
let key;
|
2010-12-06 15:51:38 -08:00
|
|
|
let id = this._store.idForGUID(guid);
|
2009-09-08 23:33:58 -07:00
|
|
|
switch (Svc.Bookmark.getItemType(id)) {
|
2010-01-25 09:33:49 -08:00
|
|
|
case Svc.Bookmark.TYPE_BOOKMARK:
|
|
|
|
key = "b" + Svc.Bookmark.getBookmarkURI(id).spec + ":" +
|
|
|
|
Svc.Bookmark.getItemTitle(id);
|
|
|
|
break;
|
2009-09-08 23:33:58 -07:00
|
|
|
case Svc.Bookmark.TYPE_FOLDER:
|
2009-11-19 21:34:17 -08:00
|
|
|
key = "f" + Svc.Bookmark.getItemTitle(id);
|
2009-09-08 23:33:58 -07:00
|
|
|
break;
|
|
|
|
case Svc.Bookmark.TYPE_SEPARATOR:
|
2009-11-19 21:34:17 -08:00
|
|
|
key = "s" + Svc.Bookmark.getItemIndex(id);
|
2009-09-08 23:33:58 -07:00
|
|
|
break;
|
2009-11-19 21:34:17 -08:00
|
|
|
default:
|
|
|
|
continue;
|
2009-09-08 23:33:58 -07:00
|
|
|
}
|
2009-11-19 21:34:17 -08:00
|
|
|
|
|
|
|
// The mapping is on a per parent-folder-name basis
|
|
|
|
let parent = Svc.Bookmark.getFolderIdForItem(id);
|
2010-12-06 15:51:56 -08:00
|
|
|
if (parent <= 0)
|
|
|
|
continue;
|
|
|
|
|
2009-11-19 21:34:17 -08:00
|
|
|
let parentName = Svc.Bookmark.getItemTitle(parent);
|
|
|
|
if (lazyMap[parentName] == null)
|
|
|
|
lazyMap[parentName] = {};
|
|
|
|
|
2010-04-29 14:36:09 -07:00
|
|
|
// If the entry already exists, remember that there are explicit dupes
|
|
|
|
let entry = new String(guid);
|
|
|
|
entry.hasDupe = lazyMap[parentName][key] != null;
|
|
|
|
|
2009-11-19 21:34:17 -08:00
|
|
|
// Remember this item's guid for its parent-name/key pair
|
2010-04-29 14:36:09 -07:00
|
|
|
lazyMap[parentName][key] = entry;
|
|
|
|
this._log.trace("Mapped: " + [parentName, key, entry, entry.hasDupe]);
|
2009-08-31 17:54:21 -07:00
|
|
|
}
|
2009-09-08 23:33:58 -07:00
|
|
|
|
2009-11-19 21:34:17 -08: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 09:33:49 -08:00
|
|
|
case "bookmark":
|
|
|
|
case "query":
|
|
|
|
case "microsummary":
|
|
|
|
key = "b" + item.bmkUri + ":" + item.title;
|
|
|
|
break;
|
2009-11-19 21:34:17 -08:00
|
|
|
case "folder":
|
|
|
|
case "livemark":
|
|
|
|
key = "f" + item.title;
|
|
|
|
break;
|
|
|
|
case "separator":
|
|
|
|
key = "s" + item.pos;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2009-09-08 23:33:58 -07:00
|
|
|
|
2009-11-19 21:34:17 -08:00
|
|
|
// Give the guid if we have the matching pair
|
2010-01-25 09:33:49 -08:00
|
|
|
this._log.trace("Finding mapping: " + item.parentName + ", " + key);
|
2009-11-19 21:34:17 -08:00
|
|
|
let parent = lazyMap[item.parentName];
|
2010-01-25 09:33:49 -08:00
|
|
|
let dupe = parent && parent[key];
|
|
|
|
this._log.trace("Mapped dupe: " + dupe);
|
|
|
|
return dupe;
|
2009-11-19 21:34:17 -08:00
|
|
|
};
|
|
|
|
});
|
2010-12-06 15:51:56 -08:00
|
|
|
|
|
|
|
this._store._childrenToOrder = {};
|
|
|
|
},
|
|
|
|
|
|
|
|
_processIncoming: function _processIncoming() {
|
|
|
|
SyncEngine.prototype._processIncoming.call(this);
|
|
|
|
// Reorder children.
|
|
|
|
this._tracker.ignoreAll = true;
|
|
|
|
this._store._orderChildren();
|
|
|
|
this._tracker.ignoreAll = false;
|
|
|
|
delete this._store._childrenToOrder;
|
2009-08-31 17:54:21 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_syncFinish: function _syncFinish() {
|
|
|
|
SyncEngine.prototype._syncFinish.call(this);
|
2009-11-19 21:34:17 -08:00
|
|
|
delete this._lazyMap;
|
2009-12-15 14:21:13 -08:00
|
|
|
this._tracker._ensureMobileQuery();
|
2009-08-31 17:54:21 -07:00
|
|
|
},
|
|
|
|
|
2010-04-29 14:36:09 -07:00
|
|
|
_createRecord: function _createRecord(id) {
|
|
|
|
// Create the record like normal but mark it as having dupes if necessary
|
|
|
|
let record = SyncEngine.prototype._createRecord.call(this, id);
|
|
|
|
let entry = this._lazyMap(record);
|
|
|
|
if (entry != null && entry.hasDupe)
|
|
|
|
record.hasDupe = true;
|
|
|
|
return record;
|
|
|
|
},
|
|
|
|
|
2009-08-31 17:27:30 -07:00
|
|
|
_findDupe: function _findDupe(item) {
|
2010-04-29 14:36:09 -07:00
|
|
|
// Don't bother finding a dupe if the incoming item has duplicates
|
|
|
|
if (item.hasDupe)
|
|
|
|
return;
|
2010-01-25 09:33:49 -08:00
|
|
|
return this._lazyMap(item);
|
2009-09-08 23:33:15 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_handleDupe: function _handleDupe(item, dupeId) {
|
2010-12-07 21:49:22 -08:00
|
|
|
// Always change the local GUID to the incoming one.
|
2009-09-08 23:33:15 -07:00
|
|
|
this._store.changeItemID(dupeId, item.id);
|
|
|
|
this._deleteId(dupeId);
|
2010-04-01 15:54:53 -07:00
|
|
|
this._tracker.addChangedID(item.id, 0);
|
2010-12-07 21:49:22 -08:00
|
|
|
if (item.parentid) {
|
|
|
|
this._tracker.addChangedID(item.parentid, 0);
|
|
|
|
}
|
2009-07-30 11:52:26 -07:00
|
|
|
}
|
2008-06-03 12:38:48 -07:00
|
|
|
};
|
|
|
|
|
2010-02-11 15:29:15 -08:00
|
|
|
function BookmarksStore(name) {
|
|
|
|
Store.call(this, name);
|
2010-08-04 05:50:44 -07:00
|
|
|
|
|
|
|
// Explicitly nullify our references to our cached services so we don't leak
|
2010-08-06 08:30:58 -07:00
|
|
|
Svc.Obs.add("places-shutdown", function() {
|
2010-08-04 05:50:44 -07:00
|
|
|
this.__bms = null;
|
|
|
|
this.__hsvc = null;
|
|
|
|
this.__ls = null;
|
|
|
|
this.__ms = null;
|
|
|
|
this.__ts = null;
|
2010-12-06 15:51:38 -08:00
|
|
|
for each ([query, stmt] in Iterator(this._stmts))
|
|
|
|
stmt.finalize();
|
2010-08-04 05:50:44 -07:00
|
|
|
}, this);
|
2008-06-03 12:38:48 -07:00
|
|
|
}
|
|
|
|
BookmarksStore.prototype = {
|
2008-11-06 19:18:46 -08:00
|
|
|
__proto__: Store.prototype,
|
2008-06-03 12:38:48 -07: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"].
|
2010-12-06 15:51:38 -08:00
|
|
|
getService(Ci.nsINavHistoryService).
|
|
|
|
QueryInterface(Ci.nsPIPlacesDatabase);
|
2008-06-03 12:38:48 -07:00
|
|
|
return this.__hsvc;
|
|
|
|
},
|
|
|
|
|
|
|
|
__ls: null,
|
|
|
|
get _ls() {
|
|
|
|
if (!this.__ls)
|
|
|
|
this.__ls = Cc["@mozilla.org/browser/livemark-service;2"].
|
2010-08-04 05:50:44 -07:00
|
|
|
getService(Ci.nsILivemarkService);
|
2008-06-03 12:38:48 -07:00
|
|
|
return this.__ls;
|
|
|
|
},
|
|
|
|
|
2010-08-04 05:50:44 -07:00
|
|
|
__ms: null,
|
2008-06-03 12:38:48 -07:00
|
|
|
get _ms() {
|
2010-08-04 05:50:44 -07:00
|
|
|
if (!this.__ms) {
|
|
|
|
try {
|
|
|
|
this.__ms = Cc["@mozilla.org/microsummary/service;1"].
|
|
|
|
getService(Ci.nsIMicrosummaryService);
|
|
|
|
} catch (e) {
|
|
|
|
this._log.warn("Could not load microsummary service");
|
|
|
|
this._log.debug(e);
|
|
|
|
// Redefine our getter so we won't keep trying to get the service
|
|
|
|
this.__defineGetter__("_ms", function() null);
|
|
|
|
}
|
2008-12-28 19:59:44 -08:00
|
|
|
}
|
2010-08-04 05:50:44 -07:00
|
|
|
return this.__ms;
|
2008-06-03 12:38:48 -07: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-28 19:59:44 -08:00
|
|
|
|
2008-12-29 23:28:17 -08:00
|
|
|
itemExists: function BStore_itemExists(id) {
|
2010-12-06 15:51:38 -08:00
|
|
|
return this.idForGUID(id) > 0;
|
2008-11-19 16:21:12 -08:00
|
|
|
},
|
|
|
|
|
2009-08-15 01:00:32 -07:00
|
|
|
applyIncoming: function BStore_applyIncoming(record) {
|
2010-12-06 15:51:56 -08:00
|
|
|
// For special folders we're only interested in child ordering.
|
|
|
|
if ((record.id in kSpecialIds) && record.children) {
|
|
|
|
this._log.debug("Processing special node: " + record.id);
|
|
|
|
// Reorder children later
|
|
|
|
this._childrenToOrder[record.id] = record.children;
|
2009-08-15 01:00:32 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Preprocess the record before doing the normal apply
|
2009-07-13 17:43:15 -07: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 01:00:32 -07:00
|
|
|
|
2009-08-15 01:00:46 -07:00
|
|
|
// Figure out the local id of the parent GUID if available
|
|
|
|
let parentGUID = record.parentid;
|
|
|
|
record._orphan = false;
|
|
|
|
if (parentGUID != null) {
|
2010-12-06 15:51:38 -08:00
|
|
|
let parentId = this.idForGUID(parentGUID);
|
2009-08-15 01:00:46 -07:00
|
|
|
|
|
|
|
// 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-15 01:00:32 -07:00
|
|
|
// Do the normal processing of incoming records
|
|
|
|
Store.prototype.applyIncoming.apply(this, arguments);
|
2009-08-15 01:00:46 -07:00
|
|
|
|
|
|
|
// Do some post-processing if we have an item
|
2010-12-06 15:51:38 -08:00
|
|
|
let itemId = this.idForGUID(record.id);
|
2009-08-15 01:00:46 -07:00
|
|
|
if (itemId > 0) {
|
2009-09-11 16:44:26 -07:00
|
|
|
// Move any children that are looking for this folder as a parent
|
2010-12-06 15:51:56 -08:00
|
|
|
if (record.type == "folder") {
|
2009-09-08 23:33:15 -07:00
|
|
|
this._reparentOrphans(itemId);
|
2010-12-06 15:51:56 -08:00
|
|
|
// Reorder children later
|
|
|
|
if (record.children)
|
|
|
|
this._childrenToOrder[record.id] = record.children;
|
|
|
|
}
|
2009-09-08 23:33:15 -07:00
|
|
|
|
2009-08-15 01:00:46 -07:00
|
|
|
// Create an annotation to remember that it needs a parent
|
|
|
|
if (record._orphan)
|
2010-12-06 15:51:48 -08:00
|
|
|
Utils.anno(itemId, PARENT_ANNO, parentGUID);
|
2009-08-15 01:00:46 -07:00
|
|
|
}
|
2009-07-13 17:43:15 -07:00
|
|
|
},
|
|
|
|
|
2009-08-15 01:07:40 -07:00
|
|
|
/**
|
|
|
|
* Find all ids of items that have a given value for an annotation
|
|
|
|
*/
|
|
|
|
_findAnnoItems: function BStore__findAnnoItems(anno, val) {
|
|
|
|
return Svc.Annos.getItemsWithAnnotation(anno, {}).filter(function(id)
|
|
|
|
Utils.anno(id, anno) == val);
|
|
|
|
},
|
|
|
|
|
2009-09-08 23:33:15 -07:00
|
|
|
/**
|
|
|
|
* For the provided parent item, attach its children to it
|
|
|
|
*/
|
|
|
|
_reparentOrphans: function _reparentOrphans(parentId) {
|
|
|
|
// Find orphans and reunite with this folder parent
|
2010-12-06 15:51:38 -08:00
|
|
|
let parentGUID = this.GUIDForId(parentId);
|
2009-09-08 23:33:15 -07:00
|
|
|
let orphans = this._findAnnoItems(PARENT_ANNO, parentGUID);
|
|
|
|
|
|
|
|
this._log.debug("Reparenting orphans " + orphans + " to " + parentId);
|
|
|
|
orphans.forEach(function(orphan) {
|
|
|
|
// Move the orphan to the parent and drop the missing parent annotation
|
2010-12-06 15:51:56 -08:00
|
|
|
Svc.Bookmark.moveItem(orphan, parentId, Svc.Bookmark.DEFAULT_INDEX);
|
2009-09-08 23:33:15 -07:00
|
|
|
Svc.Annos.removeItemAnnotation(orphan, PARENT_ANNO);
|
2009-08-18 18:42:15 -07:00
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2008-12-16 17:06:45 -08:00
|
|
|
create: function BStore_create(record) {
|
2008-06-03 12:38:48 -07:00
|
|
|
let newId;
|
2009-04-13 14:39:29 -07:00
|
|
|
switch (record.type) {
|
2008-06-03 12:38:48 -07:00
|
|
|
case "bookmark":
|
2009-07-13 17:43:15 -07:00
|
|
|
case "query":
|
2008-06-03 12:38:48 -07:00
|
|
|
case "microsummary": {
|
2009-04-13 14:39:29 -07:00
|
|
|
let uri = Utils.makeURI(record.bmkUri);
|
2010-12-06 15:51:56 -08:00
|
|
|
newId = this._bms.insertBookmark(record._parent, uri,
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX, record.title);
|
|
|
|
this._log.debug(["created bookmark", newId, "under", record._parent,
|
|
|
|
"as", record.title, record.bmkUri].join(" "));
|
2009-08-16 12:39:30 -07:00
|
|
|
|
2009-07-13 13:40:49 -07:00
|
|
|
this._tagURI(uri, record.tags);
|
2009-04-13 14:39:29 -07:00
|
|
|
this._bms.setKeywordForBookmark(newId, record.keyword);
|
2009-08-13 17:59:26 -07:00
|
|
|
if (record.description)
|
|
|
|
Utils.anno(newId, "bookmarkProperties/description", record.description);
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2009-06-16 16:16:39 -07:00
|
|
|
if (record.loadInSidebar)
|
2009-08-13 17:59:26 -07:00
|
|
|
Utils.anno(newId, "bookmarkProperties/loadInSidebar", true);
|
2009-06-16 16:16:39 -07:00
|
|
|
|
2009-04-13 14:39:29 -07:00
|
|
|
if (record.type == "microsummary") {
|
2008-06-03 12:38:48 -07:00
|
|
|
this._log.debug(" \-> is a microsummary");
|
2009-08-13 17:59:26 -07:00
|
|
|
Utils.anno(newId, "bookmarks/staticTitle", record.staticTitle || "");
|
2009-04-13 14:39:29 -07:00
|
|
|
let genURI = Utils.makeURI(record.generatorUri);
|
2010-04-02 16:37:53 -07:00
|
|
|
if (this._ms) {
|
2008-12-11 14:26:20 -08:00
|
|
|
try {
|
2008-12-28 19:59:44 -08:00
|
|
|
let micsum = this._ms.createMicrosummary(uri, genURI);
|
2008-12-11 14:26:20 -08:00
|
|
|
this._ms.setMicrosummary(newId, micsum);
|
|
|
|
}
|
|
|
|
catch(ex) { /* ignore "missing local generator" exceptions */ }
|
2010-04-02 16:37:53 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
this._log.warn("Can't create microsummary -- not supported.");
|
2008-06-03 12:38:48 -07:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case "folder":
|
2009-08-16 12:39:15 -07:00
|
|
|
newId = this._bms.createFolder(record._parent, record.title,
|
2010-12-06 15:51:56 -08:00
|
|
|
Svc.Bookmark.DEFAULT_INDEX);
|
|
|
|
this._log.debug(["created folder", newId, "under", record._parent,
|
|
|
|
"as", record.title].join(" "));
|
2010-04-01 15:11:42 -07:00
|
|
|
|
|
|
|
if (record.description)
|
|
|
|
Utils.anno(newId, "bookmarkProperties/description", record.description);
|
2010-12-06 15:51:56 -08:00
|
|
|
|
|
|
|
// record.children will be dealt with in _orderChildren.
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
|
|
|
case "livemark":
|
2009-08-26 14:22:11 -07:00
|
|
|
let siteURI = null;
|
|
|
|
if (record.siteUri != null)
|
|
|
|
siteURI = Utils.makeURI(record.siteUri);
|
|
|
|
|
|
|
|
newId = this._ls.createLivemark(record._parent, record.title, siteURI,
|
2010-12-06 15:51:56 -08:00
|
|
|
Utils.makeURI(record.feedUri),
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX);
|
|
|
|
this._log.debug(["created livemark", newId, "under", record._parent, "as",
|
|
|
|
record.title, record.siteUri, record.feedUri].join(" "));
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
|
|
|
case "separator":
|
2010-12-06 15:51:56 -08:00
|
|
|
newId = this._bms.insertSeparator(record._parent,
|
|
|
|
Svc.Bookmark.DEFAULT_INDEX);
|
|
|
|
this._log.debug(["created separator", newId, "under", record._parent]
|
|
|
|
.join(" "));
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
2009-07-09 17:15:00 -07:00
|
|
|
case "item":
|
|
|
|
this._log.debug(" -> got a generic places item.. do nothing?");
|
2009-08-15 01:04:06 -07:00
|
|
|
return;
|
2008-06-03 12:38:48 -07:00
|
|
|
default:
|
2009-04-13 14:39:29 -07:00
|
|
|
this._log.error("_create: Unknown item type: " + record.type);
|
2009-08-15 01:04:06 -07:00
|
|
|
return;
|
2008-12-05 00:39:54 -08:00
|
|
|
}
|
2009-08-15 01:04:06 -07:00
|
|
|
|
|
|
|
this._log.trace("Setting GUID of new item " + newId + " to " + record.id);
|
|
|
|
this._setGUID(newId, record.id);
|
2008-06-03 12:38:48 -07:00
|
|
|
},
|
|
|
|
|
2008-12-16 17:06:45 -08:00
|
|
|
remove: function BStore_remove(record) {
|
2010-12-06 15:51:38 -08:00
|
|
|
let itemId = this.idForGUID(record.id);
|
2009-01-06 13:54:18 -08:00
|
|
|
if (itemId <= 0) {
|
2008-12-19 11:48:09 -08:00
|
|
|
this._log.debug("Item " + record.id + " already removed");
|
2008-06-03 12:38:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var type = this._bms.getItemType(itemId);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case this._bms.TYPE_BOOKMARK:
|
2008-12-16 17:06:45 -08:00
|
|
|
this._log.debug(" -> removing bookmark " + record.id);
|
2009-04-07 21:17:40 -07:00
|
|
|
this._ts.untagURI(this._bms.getBookmarkURI(itemId), null);
|
2008-06-03 12:38:48 -07:00
|
|
|
this._bms.removeItem(itemId);
|
|
|
|
break;
|
|
|
|
case this._bms.TYPE_FOLDER:
|
2008-12-16 17:06:45 -08:00
|
|
|
this._log.debug(" -> removing folder " + record.id);
|
2009-11-18 10:24:09 -08:00
|
|
|
Svc.Bookmark.removeItem(itemId);
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
|
|
|
case this._bms.TYPE_SEPARATOR:
|
2008-12-16 17:06:45 -08:00
|
|
|
this._log.debug(" -> removing separator " + record.id);
|
2008-06-03 12:38:48 -07:00
|
|
|
this._bms.removeItem(itemId);
|
|
|
|
break;
|
|
|
|
default:
|
2008-12-16 17:06:45 -08:00
|
|
|
this._log.error("remove: Unknown item type: " + type);
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-16 17:06:45 -08:00
|
|
|
update: function BStore_update(record) {
|
2010-12-06 15:51:38 -08:00
|
|
|
let itemId = this.idForGUID(record.id);
|
2008-12-16 17:06:45 -08:00
|
|
|
|
2009-01-06 13:54:18 -08:00
|
|
|
if (itemId <= 0) {
|
2008-12-23 11:30:31 -08:00
|
|
|
this._log.debug("Skipping update for unknown item: " + record.id);
|
2008-06-03 12:38:48 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-23 11:30:31 -08:00
|
|
|
this._log.trace("Updating " + record.id + " (" + itemId + ")");
|
|
|
|
|
2010-12-06 15:51:56 -08:00
|
|
|
// Move the bookmark to a new parent or new position if necessary
|
2009-08-18 18:36:31 -07:00
|
|
|
if (Svc.Bookmark.getFolderIdForItem(itemId) != record._parent) {
|
2010-12-06 15:51:56 -08:00
|
|
|
this._log.trace("Moving item to a new parent.");
|
|
|
|
Svc.Bookmark.moveItem(itemId, record._parent, Svc.Bookmark.DEFAULT_INDEX);
|
2008-12-23 11:30:31 -08:00
|
|
|
}
|
|
|
|
|
2009-04-13 14:18:11 -07:00
|
|
|
for (let [key, val] in Iterator(record.cleartext)) {
|
2008-06-03 12:38:48 -07:00
|
|
|
switch (key) {
|
|
|
|
case "title":
|
2009-04-13 14:18:11 -07:00
|
|
|
this._bms.setItemTitle(itemId, val);
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
2009-04-13 14:39:29 -07:00
|
|
|
case "bmkUri":
|
2009-04-13 14:18:11 -07:00
|
|
|
this._bms.changeBookmarkURI(itemId, Utils.makeURI(val));
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
2009-07-13 13:40:49 -07:00
|
|
|
case "tags":
|
|
|
|
this._tagURI(this._bms.getBookmarkURI(itemId), val);
|
|
|
|
break;
|
2008-06-03 12:38:48 -07:00
|
|
|
case "keyword":
|
2009-04-13 14:18:11 -07:00
|
|
|
this._bms.setKeywordForBookmark(itemId, val);
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
|
|
|
case "description":
|
2009-08-13 17:59:26 -07:00
|
|
|
Utils.anno(itemId, "bookmarkProperties/description", val);
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
2009-06-16 16:16:39 -07:00
|
|
|
case "loadInSidebar":
|
|
|
|
if (val)
|
2009-08-13 17:59:26 -07:00
|
|
|
Utils.anno(itemId, "bookmarkProperties/loadInSidebar", true);
|
2009-06-16 16:16:39 -07:00
|
|
|
else
|
2009-08-13 17:59:26 -07:00
|
|
|
Svc.Annos.removeItemAnnotation(itemId, "bookmarkProperties/loadInSidebar");
|
2009-06-16 16:16:39 -07:00
|
|
|
break;
|
2009-04-13 14:39:29 -07:00
|
|
|
case "generatorUri": {
|
2009-01-21 19:04:13 -08:00
|
|
|
try {
|
2009-04-13 14:39:29 -07:00
|
|
|
let micsumURI = this._bms.getBookmarkURI(itemId);
|
2009-04-13 14:18:11 -07:00
|
|
|
let genURI = Utils.makeURI(val);
|
2010-04-02 16:37:53 -07:00
|
|
|
if (this._ms == SERVICE_NOT_SUPPORTED)
|
|
|
|
this._log.warn("Can't create microsummary -- not supported.");
|
|
|
|
else {
|
2009-01-21 19:04:13 -08:00
|
|
|
let micsum = this._ms.createMicrosummary(micsumURI, genURI);
|
|
|
|
this._ms.setMicrosummary(itemId, micsum);
|
2010-04-02 16:37:53 -07:00
|
|
|
}
|
2009-01-21 19:04:13 -08:00
|
|
|
} catch (e) {
|
|
|
|
this._log.debug("Could not set microsummary generator URI: " + e);
|
|
|
|
}
|
2008-06-03 12:38:48 -07:00
|
|
|
} break;
|
2009-04-13 14:39:29 -07:00
|
|
|
case "siteUri":
|
2009-04-13 14:18:11 -07:00
|
|
|
this._ls.setSiteURI(itemId, Utils.makeURI(val));
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
2009-04-13 14:39:29 -07:00
|
|
|
case "feedUri":
|
2009-04-13 14:18:11 -07:00
|
|
|
this._ls.setFeedURI(itemId, Utils.makeURI(val));
|
2008-06-03 12:38:48 -07:00
|
|
|
break;
|
2010-12-06 15:51:56 -08:00
|
|
|
case "children":
|
|
|
|
Utils.anno(itemId, CHILDREN_ANNO, val.join(","));
|
|
|
|
break;
|
2008-06-03 12:38:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-12-06 15:51:56 -08:00
|
|
|
_orderChildren: function _orderChildren() {
|
|
|
|
for (let [guid, children] in Iterator(this._childrenToOrder)) {
|
|
|
|
// Reorder children according to the GUID list. Gracefully deal
|
|
|
|
// with missing items, e.g. locally deleted.
|
|
|
|
let delta = 0;
|
|
|
|
for (let idx = 0; idx < children.length; idx++) {
|
|
|
|
let itemid = this.idForGUID(children[idx]);
|
|
|
|
if (itemid == -1) {
|
|
|
|
delta += 1;
|
|
|
|
this._log.trace("Could not locate record " + children[idx]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Svc.Bookmark.setItemIndex(itemid, idx - delta);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.debug("Could not move item " + children[idx] + ": " + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the children annotation. If there were mismatches due to local
|
|
|
|
// changes, we'll have to regenerate it from scratch, otherwise we can
|
|
|
|
// just use the incoming value.
|
|
|
|
let folderid = this.idForGUID(guid);
|
|
|
|
if (delta) {
|
|
|
|
this._updateChildrenAnno(folderid);
|
|
|
|
} else {
|
|
|
|
Utils.anno(folderid, CHILDREN_ANNO, children.join(","));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_updateChildrenAnno: function _updateChildrenAnno(itemid) {
|
|
|
|
let node = node = this._getNode(itemid);
|
|
|
|
let childids = [];
|
|
|
|
|
|
|
|
if (node.type == node.RESULT_TYPE_FOLDER &&
|
|
|
|
!this._ls.isLivemark(node.itemId)) {
|
|
|
|
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
node.containerOpen = true;
|
|
|
|
for (var i = 0; i < node.childCount; i++)
|
|
|
|
childids.push(node.getChild(i).itemId);
|
|
|
|
}
|
|
|
|
let childGUIDs = childids.map(this.GUIDForId, this);
|
|
|
|
Utils.anno(itemid, CHILDREN_ANNO, childGUIDs.join(","));
|
|
|
|
return childGUIDs;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _removeAllChildrenAnnosStm() {
|
|
|
|
let stmt = this._getStmt(
|
|
|
|
"DELETE FROM moz_items_annos " +
|
|
|
|
"WHERE anno_attribute_id = " +
|
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)");
|
|
|
|
stmt.params.anno_name = CHILDREN_ANNO;
|
|
|
|
return stmt;
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeAllChildrenAnnos: function _removeAllChildrenAnnos() {
|
|
|
|
Utils.queryAsync(this._removeAllChildrenAnnosStm);
|
|
|
|
},
|
|
|
|
|
2008-12-08 13:21:25 -08:00
|
|
|
changeItemID: function BStore_changeItemID(oldID, newID) {
|
2010-12-07 21:49:22 -08:00
|
|
|
this._log.debug("Changing GUID " + oldID + " to " + newID);
|
2009-09-08 23:33:15 -07:00
|
|
|
|
|
|
|
// Make sure there's an item to change GUIDs
|
2010-12-06 15:51:38 -08:00
|
|
|
let itemId = this.idForGUID(oldID);
|
2009-09-08 23:33:15 -07:00
|
|
|
if (itemId <= 0)
|
2008-12-05 00:39:54 -08:00
|
|
|
return;
|
2008-11-26 07:25:28 -08:00
|
|
|
|
2009-08-15 01:04:06 -07:00
|
|
|
this._setGUID(itemId, newID);
|
2010-12-06 15:51:56 -08:00
|
|
|
|
|
|
|
// Update parent
|
|
|
|
let parentid = this._bms.getFolderIdForItem(itemId);
|
|
|
|
this._updateChildrenAnno(parentid);
|
2009-08-15 01:04:06 -07:00
|
|
|
},
|
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
_getNode: function BStore__getNode(folder) {
|
2008-06-03 12:38:48 -07:00
|
|
|
let query = this._hsvc.getNewQuery();
|
|
|
|
query.setFolders([folder], 1);
|
|
|
|
return this._hsvc.executeQuery(query, this._hsvc.getNewQueryOptions()).root;
|
|
|
|
},
|
|
|
|
|
2008-12-28 19:59:44 -08: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 12:38:48 -07:00
|
|
|
}
|
2008-12-28 19:59:44 -08:00
|
|
|
return this._ts.getTagsForURI(uri, {});
|
|
|
|
},
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
_getDescription: function BStore__getDescription(id) {
|
|
|
|
try {
|
2009-08-13 17:59:26 -07:00
|
|
|
return Utils.anno(id, "bookmarkProperties/description");
|
2008-12-28 19:59:44 -08:00
|
|
|
} catch (e) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-06-16 16:16:39 -07:00
|
|
|
_isLoadInSidebar: function BStore__isLoadInSidebar(id) {
|
2009-08-13 17:59:26 -07:00
|
|
|
return Svc.Annos.itemHasAnnotation(id, "bookmarkProperties/loadInSidebar");
|
2009-06-16 16:16:39 -07:00
|
|
|
},
|
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
_getStaticTitle: function BStore__getStaticTitle(id) {
|
|
|
|
try {
|
2009-08-13 17:59:26 -07:00
|
|
|
return Utils.anno(id, "bookmarks/staticTitle");
|
2008-12-28 19:59:44 -08:00
|
|
|
} catch (e) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-12-06 15:51:56 -08:00
|
|
|
_getChildGUIDsForId: function _getChildGUIDsForId(itemid) {
|
|
|
|
let anno;
|
|
|
|
try {
|
|
|
|
anno = Utils.anno(itemid, CHILDREN_ANNO);
|
|
|
|
} catch(ex) {
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
if (anno)
|
|
|
|
return anno.split(",");
|
|
|
|
|
|
|
|
return this._updateChildrenAnno(itemid);
|
|
|
|
},
|
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
// Create a record starting from the weave id (places guid)
|
2010-11-29 16:41:17 -08:00
|
|
|
createRecord: function createRecord(id, collection) {
|
2010-12-06 15:51:38 -08:00
|
|
|
let placeId = this.idForGUID(id);
|
2010-03-25 13:58:27 -07:00
|
|
|
let record;
|
2009-01-06 13:54:18 -08:00
|
|
|
if (placeId <= 0) { // deleted item
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new PlacesItem(collection, id);
|
2009-04-03 10:38:47 -07:00
|
|
|
record.deleted = true;
|
2008-12-28 19:59:44 -08:00
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
2009-11-19 21:34:17 -08:00
|
|
|
let parent = Svc.Bookmark.getFolderIdForItem(placeId);
|
2008-12-28 19:59:44 -08:00
|
|
|
switch (this._bms.getItemType(placeId)) {
|
|
|
|
case this._bms.TYPE_BOOKMARK:
|
2009-07-13 17:43:15 -07:00
|
|
|
let bmkUri = this._bms.getBookmarkURI(placeId).spec;
|
2008-12-28 19:59:44 -08:00
|
|
|
if (this._ms && this._ms.hasMicrosummary(placeId)) {
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new BookmarkMicsum(collection, id);
|
2008-12-28 19:59:44 -08:00
|
|
|
let micsum = this._ms.getMicrosummary(placeId);
|
2009-04-13 14:39:29 -07:00
|
|
|
record.generatorUri = micsum.generator.uri.spec; // breaks local generators
|
2008-12-28 19:59:44 -08:00
|
|
|
record.staticTitle = this._getStaticTitle(placeId);
|
2009-07-13 17:43:15 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (bmkUri.search(/^place:/) == 0) {
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new BookmarkQuery(collection, id);
|
2008-06-24 18:09:41 -07:00
|
|
|
|
2009-07-13 17:43:15 -07: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
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new Bookmark(collection, id);
|
2008-12-28 19:59:44 -08:00
|
|
|
record.title = this._bms.getItemTitle(placeId);
|
2008-06-03 12:38:48 -07:00
|
|
|
}
|
|
|
|
|
2010-01-25 09:33:49 -08:00
|
|
|
record.parentName = Svc.Bookmark.getItemTitle(parent);
|
2009-07-13 17:43:15 -07:00
|
|
|
record.bmkUri = bmkUri;
|
2008-12-28 19:59:44 -08:00
|
|
|
record.tags = this._getTags(record.bmkUri);
|
|
|
|
record.keyword = this._bms.getKeywordForBookmark(placeId);
|
|
|
|
record.description = this._getDescription(placeId);
|
2009-06-16 16:16:39 -07:00
|
|
|
record.loadInSidebar = this._isLoadInSidebar(placeId);
|
2008-12-28 19:59:44 -08:00
|
|
|
break;
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
case this._bms.TYPE_FOLDER:
|
|
|
|
if (this._ls.isLivemark(placeId)) {
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new Livemark(collection, id);
|
2009-08-26 14:22:11 -07:00
|
|
|
|
|
|
|
let siteURI = this._ls.getSiteURI(placeId);
|
|
|
|
if (siteURI != null)
|
|
|
|
record.siteUri = siteURI.spec;
|
2009-04-13 14:39:29 -07:00
|
|
|
record.feedUri = this._ls.getFeedURI(placeId).spec;
|
2008-06-04 13:40:53 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
} else {
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new BookmarkFolder(collection, id);
|
2008-06-04 13:40:53 -07:00
|
|
|
}
|
2009-04-01 15:12:08 -07:00
|
|
|
|
2010-12-06 15:51:56 -08:00
|
|
|
if (parent > 0)
|
|
|
|
record.parentName = Svc.Bookmark.getItemTitle(parent);
|
2009-04-01 15:12:08 -07:00
|
|
|
record.title = this._bms.getItemTitle(placeId);
|
2010-04-01 15:11:42 -07:00
|
|
|
record.description = this._getDescription(placeId);
|
2010-12-06 15:51:56 -08:00
|
|
|
record.children = this._getChildGUIDsForId(placeId);
|
2008-12-28 19:59:44 -08:00
|
|
|
break;
|
2008-06-04 13:40:53 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
case this._bms.TYPE_SEPARATOR:
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new BookmarkSeparator(collection, id);
|
2010-12-06 15:51:56 -08:00
|
|
|
if (parent > 0)
|
|
|
|
record.parentName = Svc.Bookmark.getItemTitle(parent);
|
|
|
|
// Create a positioning identifier for the separator, used by _lazyMap
|
2009-11-19 21:34:17 -08:00
|
|
|
record.pos = Svc.Bookmark.getItemIndex(placeId);
|
2008-12-28 19:59:44 -08:00
|
|
|
break;
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
case this._bms.TYPE_DYNAMIC_CONTAINER:
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new PlacesItem(collection, id);
|
2008-12-28 19:59:44 -08:00
|
|
|
this._log.warn("Don't know how to serialize dynamic containers yet");
|
|
|
|
break;
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
default:
|
2010-11-29 16:41:17 -08:00
|
|
|
record = new PlacesItem(collection, id);
|
2008-12-28 19:59:44 -08:00
|
|
|
this._log.warn("Unknown item type, cannot serialize: " +
|
|
|
|
this._bms.getItemType(placeId));
|
2008-06-03 12:38:48 -07:00
|
|
|
}
|
|
|
|
|
2010-12-06 15:51:56 -08:00
|
|
|
record.parentid = this.GUIDForId(parent);
|
2009-10-16 16:19:28 -07:00
|
|
|
record.sortindex = this._calculateIndex(record);
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
return record;
|
2008-06-03 12:38:48 -07:00
|
|
|
},
|
|
|
|
|
2010-12-06 15:51:38 -08:00
|
|
|
_stmts: {},
|
|
|
|
_getStmt: function(query) {
|
|
|
|
if (query in this._stmts)
|
|
|
|
return this._stmts[query];
|
|
|
|
|
|
|
|
this._log.trace("Creating SQL statement: " + query);
|
|
|
|
return this._stmts[query] = Utils.createStatement(this._hsvc.DBConnection,
|
|
|
|
query);
|
|
|
|
},
|
|
|
|
|
2009-10-16 16:19:28 -07:00
|
|
|
get _frecencyStm() {
|
2010-12-06 15:51:38 -08:00
|
|
|
return this._getStmt(
|
2010-08-04 05:50:44 -07:00
|
|
|
"SELECT frecency " +
|
|
|
|
"FROM moz_places " +
|
2010-08-09 09:38:18 -07:00
|
|
|
"WHERE url = :url " +
|
|
|
|
"LIMIT 1");
|
2010-12-06 15:51:38 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
get _addGUIDAnnotationNameStm() {
|
|
|
|
let stmt = this._getStmt(
|
|
|
|
"INSERT OR IGNORE INTO moz_anno_attributes (name) VALUES (:anno_name)");
|
|
|
|
stmt.params.anno_name = GUID_ANNO;
|
|
|
|
return stmt;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _checkGUIDItemAnnotationStm() {
|
|
|
|
let stmt = this._getStmt(
|
|
|
|
"SELECT b.id AS item_id, " +
|
|
|
|
"(SELECT id FROM moz_anno_attributes WHERE name = :anno_name) AS name_id, " +
|
|
|
|
"a.id AS anno_id, a.dateAdded AS anno_date " +
|
|
|
|
"FROM moz_bookmarks b " +
|
|
|
|
"LEFT JOIN moz_items_annos a ON a.item_id = b.id " +
|
|
|
|
"AND a.anno_attribute_id = name_id " +
|
|
|
|
"WHERE b.id = :item_id");
|
|
|
|
stmt.params.anno_name = GUID_ANNO;
|
|
|
|
return stmt;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _addItemAnnotationStm() {
|
|
|
|
return this._getStmt(
|
|
|
|
"INSERT OR REPLACE INTO moz_items_annos " +
|
|
|
|
"(id, item_id, anno_attribute_id, mime_type, content, flags, " +
|
|
|
|
"expiration, type, dateAdded, lastModified) " +
|
|
|
|
"VALUES (:id, :item_id, :name_id, :mime_type, :content, :flags, " +
|
|
|
|
":expiration, :type, :date_added, :last_modified)");
|
|
|
|
},
|
|
|
|
|
|
|
|
// Some helper functions to handle GUIDs
|
|
|
|
_setGUID: function _setGUID(id, guid) {
|
|
|
|
if (arguments.length == 1)
|
|
|
|
guid = Utils.makeGUID();
|
|
|
|
|
|
|
|
// Ensure annotation name exists
|
|
|
|
Utils.queryAsync(this._addGUIDAnnotationNameStm);
|
|
|
|
|
|
|
|
let stmt = this._checkGUIDItemAnnotationStm;
|
|
|
|
stmt.params.item_id = id;
|
|
|
|
let result = Utils.queryAsync(stmt, ["item_id", "name_id", "anno_id",
|
|
|
|
"anno_date"])[0];
|
|
|
|
if (!result) {
|
2010-12-07 21:49:22 -08:00
|
|
|
this._log.warn("Couldn't annotate bookmark id " + id);
|
2010-12-06 15:51:38 -08:00
|
|
|
return guid;
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt = this._addItemAnnotationStm;
|
|
|
|
if (result.anno_id) {
|
|
|
|
stmt.params.id = result.anno_id;
|
|
|
|
stmt.params.date_added = result.anno_date;
|
|
|
|
} else {
|
|
|
|
stmt.params.id = null;
|
|
|
|
stmt.params.date_added = Date.now() * 1000;
|
2010-08-04 05:50:44 -07:00
|
|
|
}
|
2010-12-06 15:51:38 -08:00
|
|
|
stmt.params.item_id = result.item_id;
|
|
|
|
stmt.params.name_id = result.name_id;
|
|
|
|
stmt.params.content = guid;
|
|
|
|
stmt.params.flags = 0;
|
|
|
|
stmt.params.expiration = Ci.nsIAnnotationService.EXPIRE_NEVER;
|
|
|
|
stmt.params.type = Ci.nsIAnnotationService.TYPE_STRING;
|
|
|
|
stmt.params.last_modified = Date.now() * 1000;
|
|
|
|
Utils.queryAsync(stmt);
|
|
|
|
|
|
|
|
return guid;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _guidForIdStm() {
|
|
|
|
let stmt = this._getStmt(
|
|
|
|
"SELECT a.content AS guid " +
|
|
|
|
"FROM moz_items_annos a " +
|
|
|
|
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " +
|
|
|
|
"JOIN moz_bookmarks b ON b.id = a.item_id " +
|
|
|
|
"WHERE n.name = :anno_name AND b.id = :item_id");
|
|
|
|
stmt.params.anno_name = GUID_ANNO;
|
|
|
|
return stmt;
|
|
|
|
},
|
|
|
|
|
|
|
|
GUIDForId: function GUIDForId(id) {
|
|
|
|
for (let [guid, specialId] in Iterator(kSpecialIds))
|
|
|
|
if (id == specialId)
|
|
|
|
return guid;
|
|
|
|
|
|
|
|
let stmt = this._guidForIdStm;
|
|
|
|
stmt.params.item_id = id;
|
|
|
|
|
|
|
|
// Use the existing GUID if it exists
|
|
|
|
let result = Utils.queryAsync(stmt, ["guid"])[0];
|
|
|
|
if (result)
|
|
|
|
return result.guid;
|
|
|
|
|
|
|
|
// Give the uri a GUID if it doesn't have one
|
|
|
|
return this._setGUID(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
get _idForGUIDStm() {
|
|
|
|
let stmt = this._getStmt(
|
|
|
|
"SELECT a.item_id AS item_id " +
|
|
|
|
"FROM moz_items_annos a " +
|
|
|
|
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " +
|
|
|
|
"WHERE n.name = :anno_name AND a.content = :guid");
|
|
|
|
stmt.params.anno_name = GUID_ANNO;
|
|
|
|
return stmt;
|
|
|
|
},
|
|
|
|
|
|
|
|
idForGUID: function idForGUID(guid) {
|
|
|
|
if (guid in kSpecialIds)
|
|
|
|
return kSpecialIds[guid];
|
|
|
|
|
|
|
|
let stmt = this._idForGUIDStm;
|
|
|
|
// guid might be a String object rather than a string.
|
|
|
|
stmt.params.guid = guid.toString();
|
|
|
|
|
|
|
|
let result = Utils.queryAsync(stmt, ["item_id"])[0];
|
|
|
|
if (result)
|
|
|
|
return result.item_id;
|
|
|
|
return -1;
|
2009-10-16 16:19:28 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
_calculateIndex: function _calculateIndex(record) {
|
2010-11-09 13:53:50 -08:00
|
|
|
// Ensure folders have a very high sort index so they're not synced last.
|
|
|
|
if (record.type == "folder")
|
|
|
|
return FOLDER_SORTINDEX;
|
|
|
|
|
2009-10-16 16:19:28 -07:00
|
|
|
// 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) {
|
2010-08-09 09:38:18 -07:00
|
|
|
this._frecencyStm.params.url = record.bmkUri;
|
|
|
|
let result = Utils.queryAsync(this._frecencyStm, ["frecency"]);
|
|
|
|
if (result.length)
|
2010-08-09 16:59:26 -07:00
|
|
|
index += result[0].frecency;
|
2009-10-16 16:19:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
2009-08-13 18:50:54 -07:00
|
|
|
_getChildren: function BStore_getChildren(guid, items) {
|
2009-01-02 21:13:32 -08:00
|
|
|
let node = guid; // the recursion case
|
|
|
|
if (typeof(node) == "string") // callers will give us the guid as the first arg
|
2010-12-06 15:51:38 -08:00
|
|
|
node = this._getNode(this.idForGUID(guid));
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
if (node.type == node.RESULT_TYPE_FOLDER &&
|
|
|
|
!this._ls.isLivemark(node.itemId)) {
|
|
|
|
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
node.containerOpen = true;
|
2009-08-13 18:50:54 -07:00
|
|
|
|
|
|
|
// Remember all the children GUIDs and recursively get more
|
2008-12-28 19:59:44 -08:00
|
|
|
for (var i = 0; i < node.childCount; i++) {
|
|
|
|
let child = node.getChild(i);
|
2010-12-06 15:51:38 -08:00
|
|
|
items[this.GUIDForId(child.itemId)] = true;
|
2009-08-13 18:50:54 -07:00
|
|
|
this._getChildren(child, items);
|
2008-12-28 19:59:44 -08:00
|
|
|
}
|
|
|
|
}
|
2008-12-08 09:53:32 -08:00
|
|
|
|
2008-12-28 19:59:44 -08:00
|
|
|
return items;
|
2008-12-08 09:53:32 -08:00
|
|
|
},
|
|
|
|
|
2009-07-13 13:40:49 -07: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-13 17:43:15 -07:00
|
|
|
let dummyURI = Utils.makeURI("about:weave#BStore_tagURI");
|
2009-07-13 13:40:49 -07:00
|
|
|
this._ts.tagURI(dummyURI, tags);
|
|
|
|
this._ts.untagURI(bmkURI, null);
|
|
|
|
this._ts.tagURI(bmkURI, tags);
|
|
|
|
this._ts.untagURI(dummyURI, null);
|
|
|
|
},
|
2009-01-02 21:13:32 -08:00
|
|
|
|
|
|
|
getAllIDs: function BStore_getAllIDs() {
|
2010-12-06 15:51:56 -08:00
|
|
|
let items = {"menu": true,
|
|
|
|
"toolbar": true};
|
2009-08-15 00:59:49 -07:00
|
|
|
for (let [guid, id] in Iterator(kSpecialIds))
|
|
|
|
if (guid != "places" && guid != "tags")
|
|
|
|
this._getChildren(guid, items);
|
2009-01-02 13:49:19 -08:00
|
|
|
return items;
|
|
|
|
},
|
|
|
|
|
2008-06-03 12:38:48 -07:00
|
|
|
wipe: function BStore_wipe() {
|
2010-04-21 11:10:32 -07:00
|
|
|
// Save a backup before clearing out all bookmarks
|
|
|
|
archiveBookmarks();
|
2009-11-25 17:09:32 -08:00
|
|
|
|
2009-08-15 00:59:49 -07:00
|
|
|
for (let [guid, id] in Iterator(kSpecialIds))
|
|
|
|
if (guid != "places")
|
2009-04-07 21:17:40 -07:00
|
|
|
this._bms.removeFolderChildren(id);
|
2008-06-03 12:38:48 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-02-11 15:29:15 -08:00
|
|
|
function BookmarksTracker(name) {
|
|
|
|
Tracker.call(this, name);
|
2010-02-11 15:25:31 -08:00
|
|
|
|
2010-08-06 08:30:58 -07:00
|
|
|
Svc.Obs.add("places-shutdown", this);
|
|
|
|
Svc.Obs.add("weave:engine:start-tracking", this);
|
|
|
|
Svc.Obs.add("weave:engine:stop-tracking", this);
|
2008-06-03 12:38:48 -07:00
|
|
|
}
|
|
|
|
BookmarksTracker.prototype = {
|
2008-11-06 19:18:46 -08:00
|
|
|
__proto__: Tracker.prototype,
|
2008-12-05 00:39:54 -08:00
|
|
|
|
2010-08-06 08:30:58 -07:00
|
|
|
_enabled: false,
|
|
|
|
observe: function observe(subject, topic, data) {
|
|
|
|
switch (topic) {
|
|
|
|
case "weave:engine:start-tracking":
|
|
|
|
if (!this._enabled) {
|
|
|
|
Svc.Bookmark.addObserver(this, true);
|
|
|
|
this._enabled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "weave:engine:stop-tracking":
|
|
|
|
if (this._enabled) {
|
|
|
|
Svc.Bookmark.removeObserver(this);
|
|
|
|
this._enabled = false;
|
|
|
|
}
|
|
|
|
// Fall through to clean up.
|
|
|
|
case "places-shutdown":
|
|
|
|
// Explicitly nullify our references to our cached services so
|
|
|
|
// we don't leak
|
|
|
|
this.__ls = null;
|
|
|
|
this.__bms = null;
|
|
|
|
break;
|
2010-12-06 15:51:56 -08:00
|
|
|
case "weave:service:start-over":
|
|
|
|
// User has decided to stop syncing, we're going to stop tracking soon.
|
|
|
|
// This means we have to clean up the children annotations so that they
|
|
|
|
// won't be out of sync with reality if/when we start tracking again.
|
|
|
|
Engines.get("bookmarks")._store._removeAllChildrenAnnos();
|
|
|
|
break;
|
2010-08-06 08:30:58 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-08-04 05:50:44 -07:00
|
|
|
__bms: null,
|
2008-12-05 00:39:54 -08:00
|
|
|
get _bms() {
|
2010-08-04 05:50:44 -07:00
|
|
|
if (!this.__bms)
|
|
|
|
this.__bms = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
|
|
|
|
getService(Ci.nsINavBookmarksService);
|
|
|
|
return this.__bms;
|
2008-12-05 00:39:54 -08:00
|
|
|
},
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2010-08-04 05:50:44 -07:00
|
|
|
__ls: null,
|
2009-01-15 13:58:59 -08:00
|
|
|
get _ls() {
|
2010-08-04 05:50:44 -07:00
|
|
|
if (!this.__ls)
|
|
|
|
this.__ls = Cc["@mozilla.org/browser/livemark-service;2"].
|
|
|
|
getService(Ci.nsILivemarkService);
|
|
|
|
return this.__ls;
|
2009-01-15 13:58:59 -08:00
|
|
|
},
|
|
|
|
|
2009-06-17 08:51:54 -07:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsINavBookmarkObserver,
|
2010-08-04 12:07:53 -07:00
|
|
|
Ci.nsINavBookmarkObserver_MOZILLA_1_9_1_ADDITIONS,
|
|
|
|
Ci.nsISupportsWeakReference
|
2009-06-17 08:51:54 -07:00
|
|
|
]),
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2010-12-06 15:51:38 -08:00
|
|
|
_GUIDForId: function _GUIDForId(item_id) {
|
|
|
|
// Isn't indirection fun...
|
|
|
|
return Engines.get("bookmarks")._store.GUIDForId(item_id);
|
|
|
|
},
|
|
|
|
|
2010-12-06 15:51:56 -08:00
|
|
|
_updateChildrenAnno: function _updateChildrenAnno(itemid) {
|
|
|
|
return Engines.get("bookmarks")._store._updateChildrenAnno(itemid);
|
|
|
|
},
|
|
|
|
|
2009-06-17 08:51:54 -07: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) {
|
2010-12-06 15:51:38 -08:00
|
|
|
if (this.addChangedID(this._GUIDForId(itemId, true)))
|
2009-06-17 08:51:54 -07:00
|
|
|
this._upScore();
|
|
|
|
},
|
|
|
|
|
2008-11-19 16:21:12 -08:00
|
|
|
/* Every add/remove/change is worth 10 points */
|
2008-12-06 00:12:40 -08:00
|
|
|
_upScore: function BMT__upScore() {
|
2009-11-09 09:57:58 -08:00
|
|
|
this.score += 10;
|
2008-06-03 12:38:48 -07:00
|
|
|
},
|
2008-11-19 16:21:12 -08:00
|
|
|
|
2009-04-07 20:56:04 -07:00
|
|
|
/**
|
|
|
|
* Determine if a change should be ignored: we're ignoring everything or the
|
|
|
|
* folder is for livemarks
|
|
|
|
*
|
2009-06-17 08:51:54 -07:00
|
|
|
* @param itemId
|
|
|
|
* Item under consideration to ignore
|
|
|
|
* @param folder (optional)
|
2009-04-07 20:56:04 -07:00
|
|
|
* Folder of the item being changed
|
|
|
|
*/
|
2009-06-17 08:51:54 -07:00
|
|
|
_ignore: function BMT__ignore(itemId, folder) {
|
2009-04-07 20:56:04 -07:00
|
|
|
// Ignore unconditionally if the engine tells us to
|
|
|
|
if (this.ignoreAll)
|
|
|
|
return true;
|
|
|
|
|
2009-12-10 16:12:14 -08: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")) {
|
2010-12-06 15:51:38 -08:00
|
|
|
this.removeChangedID(this._GUIDForId(itemId, true));
|
2009-12-10 16:12:14 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-06-17 08:51:54 -07:00
|
|
|
// Get the folder id if we weren't given one
|
|
|
|
if (folder == null)
|
|
|
|
folder = this._bms.getFolderIdForItem(itemId);
|
|
|
|
|
2009-08-15 00:59:49 -07:00
|
|
|
let tags = kSpecialIds.tags;
|
2009-04-07 21:17:40 -07: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-07 20:56:04 -07:00
|
|
|
// Ignore livemark children
|
|
|
|
return this._ls.isLivemark(folder);
|
|
|
|
},
|
|
|
|
|
2008-12-06 00:12:40 -08:00
|
|
|
onItemAdded: function BMT_onEndUpdateBatch(itemId, folder, index) {
|
2009-06-17 08:51:54 -07:00
|
|
|
if (this._ignore(itemId, folder))
|
2009-01-15 13:58:59 -08:00
|
|
|
return;
|
2009-02-02 11:43:06 -08:00
|
|
|
|
2008-12-19 11:48:09 -08:00
|
|
|
this._log.trace("onItemAdded: " + itemId);
|
2009-06-17 08:51:54 -07:00
|
|
|
this._addId(itemId);
|
2010-12-06 15:51:56 -08:00
|
|
|
this._updateChildrenAnno(folder);
|
|
|
|
this._addId(folder);
|
2008-12-06 00:12:40 -08:00
|
|
|
},
|
|
|
|
|
2009-06-17 08:51:54 -07:00
|
|
|
onBeforeItemRemoved: function BMT_onBeforeItemRemoved(itemId) {
|
2009-06-17 08:51:54 -07:00
|
|
|
if (this._ignore(itemId))
|
2009-01-15 13:58:59 -08:00
|
|
|
return;
|
2009-02-02 11:43:06 -08:00
|
|
|
|
2009-06-17 08:51:54 -07:00
|
|
|
this._log.trace("onBeforeItemRemoved: " + itemId);
|
|
|
|
this._addId(itemId);
|
2010-12-06 15:51:56 -08:00
|
|
|
let folder = Svc.Bookmark.getFolderIdForItem(itemId);
|
|
|
|
this._updateChildrenAnno(folder);
|
|
|
|
this._addId(folder);
|
2008-06-03 12:38:48 -07:00
|
|
|
},
|
2008-11-19 16:21:12 -08:00
|
|
|
|
2009-12-10 16:12:14 -08: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 11:43:06 -08:00
|
|
|
|
2009-12-10 16:12:14 -08:00
|
|
|
// Don't continue if the Library isn't ready
|
|
|
|
let all = find("AllBookmarks");
|
|
|
|
if (all.length == 0)
|
2009-08-25 16:15:05 -07:00
|
|
|
return;
|
2009-12-10 16:12:14 -08: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-15 14:21:13 -08: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-10 16:12:14 -08:00
|
|
|
let query = Svc.Bookmark.insertBookmark(all[0], queryURI, -1, title);
|
|
|
|
Utils.anno(query, anno, "MobileBookmarks");
|
|
|
|
Utils.anno(query, "places/excludeFromBackup", 1);
|
2009-08-25 16:15:05 -07:00
|
|
|
}
|
2009-12-10 16:12:14 -08: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-25 16:15:05 -07:00
|
|
|
|
2009-02-02 11:43:06 -08:00
|
|
|
// ignore annotations except for the ones that we sync
|
2009-06-16 16:16:39 -07: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 11:43:06 -08:00
|
|
|
|
2010-01-19 11:24:00 -08:00
|
|
|
// Ignore favicon changes to avoid unnecessary churn
|
|
|
|
if (property == "favicon")
|
|
|
|
return;
|
|
|
|
|
2009-01-13 15:55:35 -08:00
|
|
|
this._log.trace("onItemChanged: " + itemId +
|
2009-01-13 16:55:51 -08:00
|
|
|
(", " + property + (isAnno? " (anno)" : "")) +
|
|
|
|
(value? (" = \"" + value + "\"") : ""));
|
2009-06-17 08:51:54 -07:00
|
|
|
this._addId(itemId);
|
2008-06-03 12:38:48 -07:00
|
|
|
},
|
|
|
|
|
2008-12-02 16:46:24 -08:00
|
|
|
onItemMoved: function BMT_onItemMoved(itemId, oldParent, oldIndex, newParent, newIndex) {
|
2009-06-17 08:51:54 -07:00
|
|
|
if (this._ignore(itemId))
|
2009-02-02 11:43:06 -08:00
|
|
|
return;
|
|
|
|
|
2008-12-06 00:12:40 -08:00
|
|
|
this._log.trace("onItemMoved: " + itemId);
|
2010-12-06 15:51:56 -08:00
|
|
|
this._updateChildrenAnno(oldParent);
|
|
|
|
this._addId(oldParent);
|
|
|
|
if (oldParent != newParent) {
|
|
|
|
this._addId(itemId);
|
|
|
|
this._updateChildrenAnno(newParent);
|
|
|
|
this._addId(newParent);
|
|
|
|
}
|
2010-02-03 15:34:42 -08:00
|
|
|
|
|
|
|
// Remove any position annotations now that the user moved the item
|
|
|
|
Svc.Annos.removeItemAnnotation(itemId, PARENT_ANNO);
|
2008-11-19 16:21:12 -08:00
|
|
|
},
|
2008-06-03 12:38:48 -07:00
|
|
|
|
2008-11-19 16:21:12 -08:00
|
|
|
onBeginUpdateBatch: function BMT_onBeginUpdateBatch() {},
|
|
|
|
onEndUpdateBatch: function BMT_onEndUpdateBatch() {},
|
2009-06-17 08:51:54 -07:00
|
|
|
onItemRemoved: function BMT_onItemRemoved(itemId, folder, index) {},
|
2008-12-02 16:46:24 -08:00
|
|
|
onItemVisited: function BMT_onItemVisited(itemId, aVisitID, time) {}
|
2008-11-06 19:18:46 -08:00
|
|
|
};
|