2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-06-07 02:28:01 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.EXPORTED_SYMBOLS = ['BookmarksEngine', "PlacesItem", "Bookmark",
|
|
|
|
"BookmarkFolder", "BookmarkQuery",
|
|
|
|
"Livemark", "BookmarkSeparator"];
|
2008-06-03 19:38:48 +00:00
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2012-02-24 12:42:32 +00:00
|
|
|
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-09-14 23:02:33 +00:00
|
|
|
Cu.import("resource://services-common/async.js");
|
|
|
|
Cu.import("resource://services-sync/constants.js");
|
2012-02-24 12:42:32 +00:00
|
|
|
Cu.import("resource://services-sync/engines.js");
|
|
|
|
Cu.import("resource://services-sync/record.js");
|
|
|
|
Cu.import("resource://services-sync/util.js");
|
2013-04-09 09:15:34 +00:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2013-04-26 02:09:52 +00:00
|
|
|
Cu.import("resource://gre/modules/PlacesBackups.jsm");
|
2012-02-24 12:42:32 +00:00
|
|
|
|
2011-03-02 23:27:16 +00:00
|
|
|
const ALLBOOKMARKS_ANNO = "AllBookmarks";
|
|
|
|
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
|
|
|
const SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
|
|
|
|
const MOBILEROOT_ANNO = "mobile/bookmarksRoot";
|
|
|
|
const MOBILE_ANNO = "MobileBookmarks";
|
|
|
|
const EXCLUDEBACKUP_ANNO = "places/excludeFromBackup";
|
2011-01-26 20:36:38 +00:00
|
|
|
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
2011-03-02 23:27:16 +00:00
|
|
|
const PARENT_ANNO = "sync/parent";
|
2011-05-17 20:53:23 +00:00
|
|
|
const ORGANIZERQUERY_ANNO = "PlacesOrganizer/OrganizerQuery";
|
2011-04-26 12:25:27 +00:00
|
|
|
const ANNOS_TO_TRACK = [DESCRIPTION_ANNO, SIDEBAR_ANNO,
|
2012-02-24 12:42:32 +00:00
|
|
|
PlacesUtils.LMANNO_FEEDURI, PlacesUtils.LMANNO_SITEURI];
|
2011-03-02 23:27:16 +00:00
|
|
|
|
|
|
|
const SERVICE_NOT_SUPPORTED = "Service not supported on this platform";
|
2010-11-09 21:53:50 +00:00
|
|
|
const FOLDER_SORTINDEX = 1000000;
|
2008-12-11 22:26:20 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.PlacesItem = function PlacesItem(collection, id, type) {
|
2011-01-19 00:23:20 +00:00
|
|
|
CryptoWrapper.call(this, collection, id);
|
|
|
|
this.type = type || "item";
|
|
|
|
}
|
|
|
|
PlacesItem.prototype = {
|
2011-03-02 23:27:16 +00:00
|
|
|
decrypt: function PlacesItem_decrypt(keyBundle) {
|
2011-01-19 00:23:20 +00:00
|
|
|
// Do the normal CryptoWrapper decrypt, but change types before returning
|
2011-03-02 23:27:16 +00:00
|
|
|
let clear = CryptoWrapper.prototype.decrypt.call(this, keyBundle);
|
2011-01-19 00:23:20 +00:00
|
|
|
|
|
|
|
// Convert the abstract places item to the actual object type
|
|
|
|
if (!this.deleted)
|
|
|
|
this.__proto__ = this.getTypeObject(this.type).prototype;
|
|
|
|
|
|
|
|
return clear;
|
|
|
|
},
|
|
|
|
|
|
|
|
getTypeObject: function PlacesItem_getTypeObject(type) {
|
|
|
|
switch (type) {
|
|
|
|
case "bookmark":
|
|
|
|
case "microsummary":
|
2011-04-26 12:25:27 +00:00
|
|
|
return Bookmark;
|
2011-01-19 00:23:20 +00:00
|
|
|
case "query":
|
|
|
|
return BookmarkQuery;
|
|
|
|
case "folder":
|
|
|
|
return BookmarkFolder;
|
|
|
|
case "livemark":
|
|
|
|
return Livemark;
|
|
|
|
case "separator":
|
|
|
|
return BookmarkSeparator;
|
|
|
|
case "item":
|
|
|
|
return PlacesItem;
|
|
|
|
}
|
|
|
|
throw "Unknown places item object type: " + type;
|
|
|
|
},
|
|
|
|
|
|
|
|
__proto__: CryptoWrapper.prototype,
|
2011-06-13 18:42:18 +00:00
|
|
|
_logName: "Sync.Record.PlacesItem",
|
2011-01-19 00:23:20 +00:00
|
|
|
};
|
|
|
|
|
2011-08-20 00:17:58 +00:00
|
|
|
Utils.deferGetSet(PlacesItem,
|
|
|
|
"cleartext",
|
|
|
|
["hasDupe", "parentid", "parentName", "type"]);
|
2011-01-19 00:23:20 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.Bookmark = function Bookmark(collection, id, type) {
|
2011-01-19 00:23:20 +00:00
|
|
|
PlacesItem.call(this, collection, id, type || "bookmark");
|
|
|
|
}
|
|
|
|
Bookmark.prototype = {
|
|
|
|
__proto__: PlacesItem.prototype,
|
2011-06-13 18:42:18 +00:00
|
|
|
_logName: "Sync.Record.Bookmark",
|
2011-01-19 00:23:20 +00:00
|
|
|
};
|
|
|
|
|
2011-08-20 00:17:58 +00:00
|
|
|
Utils.deferGetSet(Bookmark,
|
|
|
|
"cleartext",
|
|
|
|
["title", "bmkUri", "description",
|
|
|
|
"loadInSidebar", "tags", "keyword"]);
|
2011-01-19 00:23:20 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.BookmarkQuery = function BookmarkQuery(collection, id) {
|
2011-01-19 00:23:20 +00:00
|
|
|
Bookmark.call(this, collection, id, "query");
|
|
|
|
}
|
|
|
|
BookmarkQuery.prototype = {
|
|
|
|
__proto__: Bookmark.prototype,
|
2011-06-13 18:42:18 +00:00
|
|
|
_logName: "Sync.Record.BookmarkQuery",
|
2011-01-19 00:23:20 +00:00
|
|
|
};
|
|
|
|
|
2011-08-20 00:17:58 +00:00
|
|
|
Utils.deferGetSet(BookmarkQuery,
|
|
|
|
"cleartext",
|
|
|
|
["folderName", "queryId"]);
|
2011-01-19 00:23:20 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.BookmarkFolder = function BookmarkFolder(collection, id, type) {
|
2011-01-19 00:23:20 +00:00
|
|
|
PlacesItem.call(this, collection, id, type || "folder");
|
|
|
|
}
|
|
|
|
BookmarkFolder.prototype = {
|
|
|
|
__proto__: PlacesItem.prototype,
|
2011-06-13 18:42:18 +00:00
|
|
|
_logName: "Sync.Record.Folder",
|
2011-01-19 00:23:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Utils.deferGetSet(BookmarkFolder, "cleartext", ["description", "title",
|
|
|
|
"children"]);
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.Livemark = function Livemark(collection, id) {
|
2011-01-19 00:23:20 +00:00
|
|
|
BookmarkFolder.call(this, collection, id, "livemark");
|
|
|
|
}
|
|
|
|
Livemark.prototype = {
|
|
|
|
__proto__: BookmarkFolder.prototype,
|
2011-06-13 18:42:18 +00:00
|
|
|
_logName: "Sync.Record.Livemark",
|
2011-01-19 00:23:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Utils.deferGetSet(Livemark, "cleartext", ["siteUri", "feedUri"]);
|
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.BookmarkSeparator = function BookmarkSeparator(collection, id) {
|
2011-01-19 00:23:20 +00:00
|
|
|
PlacesItem.call(this, collection, id, "separator");
|
|
|
|
}
|
|
|
|
BookmarkSeparator.prototype = {
|
|
|
|
__proto__: PlacesItem.prototype,
|
2011-06-13 18:42:18 +00:00
|
|
|
_logName: "Sync.Record.Separator",
|
2011-01-19 00:23:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Utils.deferGetSet(BookmarkSeparator, "cleartext", "pos");
|
|
|
|
|
|
|
|
|
2011-01-24 18:45:27 +00:00
|
|
|
let kSpecialIds = {
|
|
|
|
|
|
|
|
// Special IDs. Note that mobile can attempt to create a record on
|
|
|
|
// dereference; special accessors are provided to prevent recursion within
|
|
|
|
// observers.
|
2011-03-02 23:27:16 +00:00
|
|
|
guids: ["menu", "places", "tags", "toolbar", "unfiled", "mobile"],
|
2011-01-24 18:45:27 +00:00
|
|
|
|
|
|
|
// Create the special mobile folder to store mobile bookmarks.
|
|
|
|
createMobileRoot: function createMobileRoot() {
|
2011-05-17 20:53:23 +00:00
|
|
|
let root = PlacesUtils.placesRootId;
|
2011-05-20 01:08:22 +00:00
|
|
|
let mRoot = PlacesUtils.bookmarks.createFolder(root, "mobile", -1);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
mRoot, MOBILEROOT_ANNO, 1, 0, PlacesUtils.annotations.EXPIRE_NEVER);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
mRoot, EXCLUDEBACKUP_ANNO, 1, 0, PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-01-24 18:45:27 +00:00
|
|
|
return mRoot;
|
|
|
|
},
|
|
|
|
|
|
|
|
findMobileRoot: function findMobileRoot(create) {
|
|
|
|
// Use the (one) mobile root if it already exists.
|
2011-05-20 01:08:22 +00:00
|
|
|
let root = PlacesUtils.annotations.getItemsWithAnnotation(MOBILEROOT_ANNO, {});
|
2011-01-24 18:45:27 +00:00
|
|
|
if (root.length != 0)
|
|
|
|
return root[0];
|
|
|
|
|
|
|
|
if (create)
|
|
|
|
return this.createMobileRoot();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Accessors for IDs.
|
|
|
|
isSpecialGUID: function isSpecialGUID(g) {
|
|
|
|
return this.guids.indexOf(g) != -1;
|
|
|
|
},
|
|
|
|
|
|
|
|
specialIdForGUID: function specialIdForGUID(guid, create) {
|
|
|
|
if (guid == "mobile") {
|
|
|
|
return this.findMobileRoot(create);
|
|
|
|
}
|
|
|
|
return this[guid];
|
|
|
|
},
|
|
|
|
|
|
|
|
// Don't bother creating mobile: if it doesn't exist, this ID can't be it!
|
|
|
|
specialGUIDForId: function specialGUIDForId(id) {
|
|
|
|
for each (let guid in this.guids)
|
|
|
|
if (this.specialIdForGUID(guid, false) == id)
|
|
|
|
return guid;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2011-05-17 20:53:23 +00:00
|
|
|
get menu() PlacesUtils.bookmarksMenuFolderId,
|
|
|
|
get places() PlacesUtils.placesRootId,
|
|
|
|
get tags() PlacesUtils.tagsFolderId,
|
|
|
|
get toolbar() PlacesUtils.toolbarFolderId,
|
|
|
|
get unfiled() PlacesUtils.unfiledBookmarksFolderId,
|
2011-01-24 18:45:27 +00:00
|
|
|
get mobile() this.findMobileRoot(true),
|
|
|
|
};
|
2009-06-17 16:28:15 +00:00
|
|
|
|
2012-10-31 16:13:28 +00:00
|
|
|
this.BookmarksEngine = function BookmarksEngine(service) {
|
2012-08-29 21:43:41 +00:00
|
|
|
SyncEngine.call(this, "Bookmarks", service);
|
2008-06-25 04:15:14 +00:00
|
|
|
}
|
|
|
|
BookmarksEngine.prototype = {
|
2008-12-05 08:39:54 +00:00
|
|
|
__proto__: SyncEngine.prototype,
|
2009-04-13 19:54:31 +00:00
|
|
|
_recordObj: PlacesItem,
|
2009-01-06 21:54:18 +00:00
|
|
|
_storeObj: BookmarksStore,
|
2009-07-30 18:52:26 +00:00
|
|
|
_trackerObj: BookmarksTracker,
|
2010-12-06 23:51:38 +00:00
|
|
|
version: 2,
|
2009-07-30 18:52:26 +00:00
|
|
|
|
2011-05-20 01:08:22 +00:00
|
|
|
_sync: function _sync() {
|
|
|
|
let engine = this;
|
|
|
|
let batchEx = null;
|
|
|
|
|
|
|
|
// Try running sync in batch mode
|
|
|
|
PlacesUtils.bookmarks.runInBatchMode({
|
|
|
|
runBatched: function wrappedSync() {
|
|
|
|
try {
|
|
|
|
SyncEngine.prototype._sync.call(engine);
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
batchEx = ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, null);
|
|
|
|
|
|
|
|
// Expose the exception if something inside the batch failed
|
2011-06-15 07:03:34 +00:00
|
|
|
if (batchEx != null) {
|
2011-05-20 01:08:22 +00:00
|
|
|
throw batchEx;
|
|
|
|
}
|
|
|
|
},
|
2009-09-01 00:27:30 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
_guidMapFailed: false,
|
|
|
|
_buildGUIDMap: function _buildGUIDMap() {
|
|
|
|
let guidMap = {};
|
|
|
|
for (let guid in this._store.getAllIDs()) {
|
|
|
|
// Figure out with which key to store the mapping.
|
|
|
|
let key;
|
|
|
|
let id = this._store.idForGUID(guid);
|
|
|
|
switch (PlacesUtils.bookmarks.getItemType(id)) {
|
|
|
|
case PlacesUtils.bookmarks.TYPE_BOOKMARK:
|
|
|
|
|
|
|
|
// Smart bookmarks map to their annotation value.
|
|
|
|
let queryId;
|
|
|
|
try {
|
|
|
|
queryId = PlacesUtils.annotations.getItemAnnotation(
|
|
|
|
id, SMART_BOOKMARKS_ANNO);
|
|
|
|
} catch(ex) {}
|
|
|
|
|
|
|
|
if (queryId)
|
|
|
|
key = "q" + queryId;
|
|
|
|
else
|
|
|
|
key = "b" + PlacesUtils.bookmarks.getBookmarkURI(id).spec + ":" +
|
|
|
|
PlacesUtils.bookmarks.getItemTitle(id);
|
|
|
|
break;
|
|
|
|
case PlacesUtils.bookmarks.TYPE_FOLDER:
|
|
|
|
key = "f" + PlacesUtils.bookmarks.getItemTitle(id);
|
|
|
|
break;
|
|
|
|
case PlacesUtils.bookmarks.TYPE_SEPARATOR:
|
|
|
|
key = "s" + PlacesUtils.bookmarks.getItemIndex(id);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-01 00:54:21 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
// The mapping is on a per parent-folder-name basis.
|
|
|
|
let parent = PlacesUtils.bookmarks.getFolderIdForItem(id);
|
|
|
|
if (parent <= 0)
|
|
|
|
continue;
|
2010-04-21 18:10:32 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
let parentName = PlacesUtils.bookmarks.getItemTitle(parent);
|
|
|
|
if (guidMap[parentName] == null)
|
|
|
|
guidMap[parentName] = {};
|
2009-11-20 05:34:17 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
// If the entry already exists, remember that there are explicit dupes.
|
|
|
|
let entry = new String(guid);
|
|
|
|
entry.hasDupe = guidMap[parentName][key] != null;
|
|
|
|
|
|
|
|
// Remember this item's GUID for its parent-name/key pair.
|
|
|
|
guidMap[parentName][key] = entry;
|
|
|
|
this._log.trace("Mapped: " + [parentName, key, entry, entry.hasDupe]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return guidMap;
|
|
|
|
},
|
2010-12-06 23:51:56 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
// Helper function to get a dupe GUID for an item.
|
|
|
|
_mapDupe: function _mapDupe(item) {
|
|
|
|
// Figure out if we have something to key with.
|
|
|
|
let key;
|
|
|
|
let altKey;
|
|
|
|
switch (item.type) {
|
|
|
|
case "query":
|
|
|
|
// Prior to Bug 610501, records didn't carry their Smart Bookmark
|
|
|
|
// anno, so we won't be able to dupe them correctly. This altKey
|
|
|
|
// hack should get them to dupe correctly.
|
|
|
|
if (item.queryId) {
|
|
|
|
key = "q" + item.queryId;
|
|
|
|
altKey = "b" + item.bmkUri + ":" + item.title;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// No queryID? Fall through to the regular bookmark case.
|
|
|
|
case "bookmark":
|
|
|
|
case "microsummary":
|
|
|
|
key = "b" + item.bmkUri + ":" + item.title;
|
|
|
|
break;
|
|
|
|
case "folder":
|
|
|
|
case "livemark":
|
|
|
|
key = "f" + item.title;
|
|
|
|
break;
|
|
|
|
case "separator":
|
|
|
|
key = "s" + item.pos;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2009-11-20 05:34:17 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
// Figure out if we have a map to use!
|
|
|
|
// This will throw in some circumstances. That's fine.
|
|
|
|
let guidMap = this._guidMap;
|
2010-04-29 21:36:09 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
// Give the GUID if we have the matching pair.
|
|
|
|
this._log.trace("Finding mapping: " + item.parentName + ", " + key);
|
|
|
|
let parent = guidMap[item.parentName];
|
|
|
|
|
|
|
|
if (!parent) {
|
|
|
|
this._log.trace("No parent => no dupe.");
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
let dupe = parent[key];
|
|
|
|
|
|
|
|
if (dupe) {
|
|
|
|
this._log.trace("Mapped dupe: " + dupe);
|
|
|
|
return dupe;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (altKey) {
|
|
|
|
dupe = parent[altKey];
|
|
|
|
if (dupe) {
|
|
|
|
this._log.trace("Mapped dupe using altKey " + altKey + ": " + dupe);
|
|
|
|
return dupe;
|
2009-09-01 00:54:21 +00:00
|
|
|
}
|
2011-06-15 07:03:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this._log.trace("No dupe found for key " + key + "/" + altKey + ".");
|
|
|
|
return undefined;
|
|
|
|
},
|
2009-09-09 06:33:58 +00:00
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
_syncStartup: function _syncStart() {
|
|
|
|
SyncEngine.prototype._syncStartup.call(this);
|
2009-09-09 06:33:58 +00:00
|
|
|
|
2013-04-09 09:15:34 +00:00
|
|
|
let cb = Async.makeSpinningCallback();
|
|
|
|
Task.spawn(function() {
|
|
|
|
// For first-syncs, make a backup for the user to restore
|
|
|
|
if (this.lastSync == 0) {
|
2014-05-09 04:14:34 +00:00
|
|
|
this._log.debug("Bookmarks backup starting.");
|
2013-04-26 02:09:52 +00:00
|
|
|
yield PlacesBackups.create(null, true);
|
2014-05-09 04:14:34 +00:00
|
|
|
this._log.debug("Bookmarks backup done.");
|
2011-06-15 07:03:34 +00:00
|
|
|
}
|
2014-05-09 04:14:34 +00:00
|
|
|
}.bind(this)).then(
|
|
|
|
cb, ex => {
|
|
|
|
// Failure to create a backup is somewhat bad, but probably not bad
|
|
|
|
// enough to prevent syncing of bookmarks - so just log the error and
|
|
|
|
// continue.
|
|
|
|
this._log.warn("Got exception \"" + Utils.exceptionStr(ex) +
|
|
|
|
"\" backing up bookmarks, but continuing with sync.");
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
);
|
2010-12-06 23:51:56 +00:00
|
|
|
|
2013-04-09 09:15:34 +00:00
|
|
|
cb.wait();
|
2014-05-09 04:14:34 +00:00
|
|
|
|
|
|
|
this.__defineGetter__("_guidMap", function() {
|
|
|
|
// Create a mapping of folder titles and separator positions to GUID.
|
|
|
|
// We do this lazily so that we don't do any work unless we reconcile
|
|
|
|
// incoming items.
|
|
|
|
let guidMap;
|
|
|
|
try {
|
|
|
|
guidMap = this._buildGUIDMap();
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Got exception \"" + Utils.exceptionStr(ex) +
|
|
|
|
"\" building GUID map." +
|
|
|
|
" Skipping all other incoming items.");
|
|
|
|
throw {code: Engine.prototype.eEngineAbortApplyIncoming,
|
|
|
|
cause: ex};
|
|
|
|
}
|
|
|
|
delete this._guidMap;
|
|
|
|
return this._guidMap = guidMap;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._store._childrenToOrder = {};
|
2010-12-06 23:51:56 +00:00
|
|
|
},
|
|
|
|
|
2012-12-14 22:00:40 +00:00
|
|
|
_processIncoming: function (newitems) {
|
2011-01-04 23:04:18 +00:00
|
|
|
try {
|
2012-12-14 22:00:40 +00:00
|
|
|
SyncEngine.prototype._processIncoming.call(this, newitems);
|
2011-01-04 23:04:18 +00:00
|
|
|
} finally {
|
|
|
|
// Reorder children.
|
|
|
|
this._tracker.ignoreAll = true;
|
|
|
|
this._store._orderChildren();
|
|
|
|
this._tracker.ignoreAll = false;
|
|
|
|
delete this._store._childrenToOrder;
|
|
|
|
}
|
2009-09-01 00:54:21 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_syncFinish: function _syncFinish() {
|
|
|
|
SyncEngine.prototype._syncFinish.call(this);
|
2009-12-15 22:21:13 +00:00
|
|
|
this._tracker._ensureMobileQuery();
|
2009-09-01 00:54:21 +00:00
|
|
|
},
|
|
|
|
|
2011-06-15 07:03:34 +00:00
|
|
|
_syncCleanup: function _syncCleanup() {
|
|
|
|
SyncEngine.prototype._syncCleanup.call(this);
|
|
|
|
delete this._guidMap;
|
|
|
|
},
|
|
|
|
|
2010-04-29 21:36:09 +00:00
|
|
|
_createRecord: function _createRecord(id) {
|
2012-12-14 22:00:40 +00:00
|
|
|
// Create the record as usual, but mark it as having dupes if necessary.
|
2010-04-29 21:36:09 +00:00
|
|
|
let record = SyncEngine.prototype._createRecord.call(this, id);
|
2011-06-15 07:03:34 +00:00
|
|
|
let entry = this._mapDupe(record);
|
2012-12-14 22:00:40 +00:00
|
|
|
if (entry != null && entry.hasDupe) {
|
2010-04-29 21:36:09 +00:00
|
|
|
record.hasDupe = true;
|
2012-12-14 22:00:40 +00:00
|
|
|
}
|
2010-04-29 21:36:09 +00:00
|
|
|
return record;
|
|
|
|
},
|
|
|
|
|
2009-09-01 00:27:30 +00:00
|
|
|
_findDupe: function _findDupe(item) {
|
2012-12-14 22:00:40 +00:00
|
|
|
this._log.trace("Finding dupe for " + item.id +
|
|
|
|
" (already duped: " + item.hasDupe + ").");
|
|
|
|
|
|
|
|
// Don't bother finding a dupe if the incoming item has duplicates.
|
|
|
|
if (item.hasDupe) {
|
|
|
|
this._log.trace(item.id + " already a dupe: not finding one.");
|
2010-04-29 21:36:09 +00:00
|
|
|
return;
|
2012-12-14 22:00:40 +00:00
|
|
|
}
|
|
|
|
let mapped = this._mapDupe(item);
|
|
|
|
this._log.debug(item.id + " mapped to " + mapped);
|
|
|
|
return mapped;
|
2009-07-30 18:52:26 +00:00
|
|
|
}
|
2008-06-03 19:38:48 +00:00
|
|
|
};
|
|
|
|
|
2012-08-29 21:43:41 +00:00
|
|
|
function BookmarksStore(name, engine) {
|
|
|
|
Store.call(this, name, engine);
|
2010-08-04 12:50:44 +00:00
|
|
|
|
|
|
|
// Explicitly nullify our references to our cached services so we don't leak
|
2010-08-06 15:30:58 +00:00
|
|
|
Svc.Obs.add("places-shutdown", function() {
|
2014-03-19 13:33:02 +00:00
|
|
|
for each (let [query, stmt] in Iterator(this._stmts)) {
|
2010-12-06 23:51:38 +00:00
|
|
|
stmt.finalize();
|
2011-08-27 02:14:09 +00:00
|
|
|
}
|
|
|
|
this._stmts = {};
|
2010-08-04 12:50:44 +00:00
|
|
|
}, this);
|
2008-06-03 19:38:48 +00:00
|
|
|
}
|
|
|
|
BookmarksStore.prototype = {
|
2008-11-07 03:18:46 +00:00
|
|
|
__proto__: Store.prototype,
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2008-12-30 07:28:17 +00:00
|
|
|
itemExists: function BStore_itemExists(id) {
|
2011-01-24 18:45:27 +00:00
|
|
|
return this.idForGUID(id, true) > 0;
|
2008-11-20 00:21:12 +00:00
|
|
|
},
|
2011-01-28 08:18:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the record is a tag query, rewrite it to refer to the local tag ID.
|
|
|
|
*
|
|
|
|
* Otherwise, just return.
|
|
|
|
*/
|
|
|
|
preprocessTagQuery: function preprocessTagQuery(record) {
|
|
|
|
if (record.type != "query" ||
|
|
|
|
record.bmkUri == null ||
|
2012-10-29 22:24:52 +00:00
|
|
|
!record.folderName)
|
2011-01-28 08:18:36 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Yes, this works without chopping off the "place:" prefix.
|
|
|
|
let uri = record.bmkUri
|
|
|
|
let queriesRef = {};
|
|
|
|
let queryCountRef = {};
|
|
|
|
let optionsRef = {};
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.history.queryStringToQueries(uri, queriesRef, queryCountRef,
|
|
|
|
optionsRef);
|
2011-01-28 08:18:36 +00:00
|
|
|
|
|
|
|
// We only process tag URIs.
|
|
|
|
if (optionsRef.value.resultType != optionsRef.value.RESULTS_AS_TAG_CONTENTS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Tag something to ensure that the tag exists.
|
|
|
|
let tag = record.folderName;
|
|
|
|
let dummyURI = Utils.makeURI("about:weave#BStore_preprocess");
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.tagging.tagURI(dummyURI, [tag]);
|
2011-01-28 08:18:36 +00:00
|
|
|
|
|
|
|
// Look for the id of the tag, which might just have been added.
|
2011-05-17 20:53:23 +00:00
|
|
|
let tags = this._getNode(PlacesUtils.tagsFolderId);
|
2011-01-28 08:18:36 +00:00
|
|
|
if (!(tags instanceof Ci.nsINavHistoryQueryResultNode)) {
|
|
|
|
this._log.debug("tags isn't an nsINavHistoryQueryResultNode; aborting.");
|
|
|
|
return;
|
|
|
|
}
|
2008-11-20 00:21:12 +00:00
|
|
|
|
2011-01-28 08:18:36 +00:00
|
|
|
tags.containerOpen = true;
|
2011-04-23 00:08:36 +00:00
|
|
|
try {
|
|
|
|
for (let i = 0; i < tags.childCount; i++) {
|
|
|
|
let child = tags.getChild(i);
|
|
|
|
if (child.title == tag) {
|
|
|
|
// Found the tag, so fix up the query to use the right id.
|
|
|
|
this._log.debug("Tag query folder: " + tag + " = " + child.itemId);
|
|
|
|
|
|
|
|
this._log.trace("Replacing folders in: " + uri);
|
|
|
|
for each (let q in queriesRef.value)
|
|
|
|
q.setFolders([child.itemId], 1);
|
|
|
|
|
2011-05-20 01:08:22 +00:00
|
|
|
record.bmkUri = PlacesUtils.history.queriesToQueryString(
|
|
|
|
queriesRef.value, queryCountRef.value, optionsRef.value);
|
2011-04-23 00:08:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-01-28 08:18:36 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-23 00:08:36 +00:00
|
|
|
finally {
|
|
|
|
tags.containerOpen = false;
|
|
|
|
}
|
2011-01-28 08:18:36 +00:00
|
|
|
},
|
|
|
|
|
2009-08-15 08:00:32 +00:00
|
|
|
applyIncoming: function BStore_applyIncoming(record) {
|
2012-12-14 22:00:40 +00:00
|
|
|
this._log.debug("Applying record " + record.id);
|
2012-12-05 00:49:55 +00:00
|
|
|
let isSpecial = record.id in kSpecialIds;
|
|
|
|
|
2011-01-14 21:41:09 +00:00
|
|
|
if (record.deleted) {
|
2012-12-05 00:49:55 +00:00
|
|
|
if (isSpecial) {
|
|
|
|
this._log.warn("Ignoring deletion for special record " + record.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't bother with pre and post-processing for deletions.
|
2011-03-02 23:27:16 +00:00
|
|
|
Store.prototype.applyIncoming.call(this, record);
|
2011-01-14 21:41:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-12-06 23:51:56 +00:00
|
|
|
// For special folders we're only interested in child ordering.
|
2012-12-05 00:49:55 +00:00
|
|
|
if (isSpecial && record.children) {
|
2010-12-06 23:51:56 +00:00
|
|
|
this._log.debug("Processing special node: " + record.id);
|
|
|
|
// Reorder children later
|
|
|
|
this._childrenToOrder[record.id] = record.children;
|
2009-08-15 08:00:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-29 22:24:52 +00:00
|
|
|
// Skip malformed records. (Bug 806460.)
|
|
|
|
if (record.type == "query" &&
|
|
|
|
!record.bmkUri) {
|
|
|
|
this._log.warn("Skipping malformed query bookmark: " + record.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-28 08:18:36 +00:00
|
|
|
// Preprocess the record before doing the normal apply.
|
|
|
|
this.preprocessTagQuery(record);
|
2009-08-15 08:00:32 +00:00
|
|
|
|
2009-08-15 08:00:46 +00:00
|
|
|
// Figure out the local id of the parent GUID if available
|
|
|
|
let parentGUID = record.parentid;
|
2011-01-14 21:41:09 +00:00
|
|
|
if (!parentGUID) {
|
|
|
|
throw "Record " + record.id + " has invalid parentid: " + parentGUID;
|
|
|
|
}
|
2012-12-14 22:00:40 +00:00
|
|
|
this._log.debug("Local parent is " + parentGUID);
|
2009-08-15 08:00:46 +00:00
|
|
|
|
2011-01-14 21:41:09 +00:00
|
|
|
let parentId = this.idForGUID(parentGUID);
|
|
|
|
if (parentId > 0) {
|
2009-08-15 08:00:46 +00:00
|
|
|
// Save the parent id for modifying the bookmark later
|
|
|
|
record._parent = parentId;
|
2011-01-14 21:41:09 +00:00
|
|
|
record._orphan = false;
|
2012-12-14 22:00:40 +00:00
|
|
|
this._log.debug("Record " + record.id + " is not an orphan.");
|
2011-01-14 21:41:09 +00:00
|
|
|
} else {
|
|
|
|
this._log.trace("Record " + record.id +
|
|
|
|
" is an orphan: could not find parent " + parentGUID);
|
|
|
|
record._orphan = true;
|
2009-08-15 08:00:46 +00:00
|
|
|
}
|
|
|
|
|
2009-08-15 08:00:32 +00:00
|
|
|
// Do the normal processing of incoming records
|
2011-03-02 23:27:16 +00:00
|
|
|
Store.prototype.applyIncoming.call(this, record);
|
2009-08-15 08:00:46 +00:00
|
|
|
|
|
|
|
// Do some post-processing if we have an item
|
2010-12-06 23:51:38 +00:00
|
|
|
let itemId = this.idForGUID(record.id);
|
2009-08-15 08:00:46 +00:00
|
|
|
if (itemId > 0) {
|
2009-09-11 23:44:26 +00:00
|
|
|
// Move any children that are looking for this folder as a parent
|
2010-12-06 23:51:56 +00:00
|
|
|
if (record.type == "folder") {
|
2009-09-09 06:33:15 +00:00
|
|
|
this._reparentOrphans(itemId);
|
2010-12-06 23:51:56 +00:00
|
|
|
// Reorder children later
|
|
|
|
if (record.children)
|
|
|
|
this._childrenToOrder[record.id] = record.children;
|
|
|
|
}
|
2009-09-09 06:33:15 +00:00
|
|
|
|
2011-01-14 21:41:09 +00:00
|
|
|
// Create an annotation to remember that it needs reparenting.
|
2011-03-02 23:27:16 +00:00
|
|
|
if (record._orphan) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
itemId, PARENT_ANNO, parentGUID, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-03-02 23:27:16 +00:00
|
|
|
}
|
2009-08-15 08:00:46 +00:00
|
|
|
}
|
2009-07-14 00:43:15 +00:00
|
|
|
},
|
|
|
|
|
2009-08-15 08:07:40 +00:00
|
|
|
/**
|
|
|
|
* Find all ids of items that have a given value for an annotation
|
|
|
|
*/
|
|
|
|
_findAnnoItems: function BStore__findAnnoItems(anno, val) {
|
2011-05-20 01:08:22 +00:00
|
|
|
return PlacesUtils.annotations.getItemsWithAnnotation(anno, {})
|
|
|
|
.filter(function(id) {
|
|
|
|
return PlacesUtils.annotations.getItemAnnotation(id, anno) == val;
|
|
|
|
});
|
2009-08-15 08:07:40 +00:00
|
|
|
},
|
|
|
|
|
2009-09-09 06:33:15 +00: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 23:51:38 +00:00
|
|
|
let parentGUID = this.GUIDForId(parentId);
|
2009-09-09 06:33:15 +00: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
|
2011-01-14 21:41:09 +00:00
|
|
|
if (this._reparentItem(orphan, parentId)) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.removeItemAnnotation(orphan, PARENT_ANNO);
|
2011-01-14 21:41:09 +00:00
|
|
|
}
|
2009-08-19 01:42:15 +00:00
|
|
|
}, this);
|
|
|
|
},
|
|
|
|
|
2011-01-14 21:41:09 +00:00
|
|
|
_reparentItem: function _reparentItem(itemId, parentId) {
|
|
|
|
this._log.trace("Attempting to move item " + itemId + " to new parent " +
|
|
|
|
parentId);
|
|
|
|
try {
|
|
|
|
if (parentId > 0) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.moveItem(itemId, parentId,
|
|
|
|
PlacesUtils.bookmarks.DEFAULT_INDEX);
|
2011-01-14 21:41:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} catch(ex) {
|
|
|
|
this._log.debug("Failed to reparent item. " + Utils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2011-02-23 20:14:11 +00:00
|
|
|
// Turn a record's nsINavBookmarksService constant and other attributes into
|
|
|
|
// a granular type for comparison.
|
|
|
|
_recordType: function _recordType(itemId) {
|
2011-05-20 01:08:22 +00:00
|
|
|
let bms = PlacesUtils.bookmarks;
|
2011-02-23 20:14:11 +00:00
|
|
|
let type = bms.getItemType(itemId);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case bms.TYPE_FOLDER:
|
2012-02-24 12:42:32 +00:00
|
|
|
if (PlacesUtils.annotations
|
|
|
|
.itemHasAnnotation(itemId, PlacesUtils.LMANNO_FEEDURI)) {
|
2011-02-23 20:14:11 +00:00
|
|
|
return "livemark";
|
2012-02-24 12:42:32 +00:00
|
|
|
}
|
2011-02-23 20:14:11 +00:00
|
|
|
return "folder";
|
|
|
|
|
|
|
|
case bms.TYPE_BOOKMARK:
|
|
|
|
let bmkUri = bms.getBookmarkURI(itemId).spec;
|
2012-02-24 12:42:32 +00:00
|
|
|
if (bmkUri.indexOf("place:") == 0) {
|
2011-02-23 20:14:11 +00:00
|
|
|
return "query";
|
2012-02-24 12:42:32 +00:00
|
|
|
}
|
2011-02-23 20:14:11 +00:00
|
|
|
return "bookmark";
|
|
|
|
|
|
|
|
case bms.TYPE_SEPARATOR:
|
|
|
|
return "separator";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-17 01:06:45 +00:00
|
|
|
create: function BStore_create(record) {
|
2011-02-25 19:56:58 +00:00
|
|
|
// Default to unfiled if we don't have the parent yet.
|
|
|
|
|
|
|
|
// Valid parent IDs are all positive integers. Other values -- undefined,
|
|
|
|
// null, -1 -- all compare false for > 0, so this catches them all. We
|
|
|
|
// don't just use <= without the !, because undefined and null compare
|
|
|
|
// false for that, too!
|
|
|
|
if (!(record._parent > 0)) {
|
|
|
|
this._log.debug("Parent is " + record._parent + "; reparenting to unfiled.");
|
2011-01-14 21:41:09 +00:00
|
|
|
record._parent = kSpecialIds.unfiled;
|
|
|
|
}
|
|
|
|
|
2008-06-03 19:38:48 +00:00
|
|
|
let newId;
|
2009-04-13 21:39:29 +00:00
|
|
|
switch (record.type) {
|
2008-06-03 19:38:48 +00:00
|
|
|
case "bookmark":
|
2009-07-14 00:43:15 +00:00
|
|
|
case "query":
|
2008-06-03 19:38:48 +00:00
|
|
|
case "microsummary": {
|
2009-04-13 21:39:29 +00:00
|
|
|
let uri = Utils.makeURI(record.bmkUri);
|
2011-05-20 01:08:22 +00:00
|
|
|
newId = PlacesUtils.bookmarks.insertBookmark(
|
|
|
|
record._parent, uri, PlacesUtils.bookmarks.DEFAULT_INDEX, record.title);
|
2011-03-02 23:27:16 +00:00
|
|
|
this._log.debug("created bookmark " + newId + " under " + record._parent
|
|
|
|
+ " as " + record.title + " " + record.bmkUri);
|
2009-08-16 19:39:30 +00:00
|
|
|
|
2011-01-26 20:36:38 +00:00
|
|
|
// Smart bookmark annotations are strings.
|
|
|
|
if (record.queryId) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
newId, SMART_BOOKMARKS_ANNO, record.queryId, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-01-26 20:36:38 +00:00
|
|
|
}
|
|
|
|
|
2011-08-26 17:26:11 +00:00
|
|
|
if (Array.isArray(record.tags)) {
|
2011-01-14 21:41:09 +00:00
|
|
|
this._tagURI(uri, record.tags);
|
|
|
|
}
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.setKeywordForBookmark(newId, record.keyword);
|
2011-03-02 23:27:16 +00:00
|
|
|
if (record.description) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
newId, DESCRIPTION_ANNO, record.description, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-03-02 23:27:16 +00:00
|
|
|
}
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2011-03-02 23:27:16 +00:00
|
|
|
if (record.loadInSidebar) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
newId, SIDEBAR_ANNO, true, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-03-02 23:27:16 +00:00
|
|
|
}
|
2009-06-16 23:16:39 +00:00
|
|
|
|
2008-06-03 19:38:48 +00:00
|
|
|
} break;
|
|
|
|
case "folder":
|
2011-05-20 01:08:22 +00:00
|
|
|
newId = PlacesUtils.bookmarks.createFolder(
|
|
|
|
record._parent, record.title, PlacesUtils.bookmarks.DEFAULT_INDEX);
|
2011-03-02 23:27:16 +00:00
|
|
|
this._log.debug("created folder " + newId + " under " + record._parent
|
|
|
|
+ " as " + record.title);
|
2010-04-01 22:11:42 +00:00
|
|
|
|
2011-03-02 23:27:16 +00:00
|
|
|
if (record.description) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
newId, DESCRIPTION_ANNO, record.description, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-03-02 23:27:16 +00:00
|
|
|
}
|
2010-12-06 23:51:56 +00:00
|
|
|
|
|
|
|
// record.children will be dealt with in _orderChildren.
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
|
|
|
case "livemark":
|
2009-08-26 21:22:11 +00:00
|
|
|
let siteURI = null;
|
2011-02-25 19:56:58 +00:00
|
|
|
if (!record.feedUri) {
|
|
|
|
this._log.debug("No feed URI: skipping livemark record " + record.id);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-24 12:42:32 +00:00
|
|
|
if (PlacesUtils.annotations
|
|
|
|
.itemHasAnnotation(record._parent, PlacesUtils.LMANNO_FEEDURI)) {
|
2011-02-25 19:56:58 +00:00
|
|
|
this._log.debug("Invalid parent: skipping livemark record " + record.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-26 21:22:11 +00:00
|
|
|
if (record.siteUri != null)
|
|
|
|
siteURI = Utils.makeURI(record.siteUri);
|
|
|
|
|
2012-02-24 12:42:32 +00:00
|
|
|
// Until this engine can handle asynchronous error reporting, we need to
|
|
|
|
// detect errors on creation synchronously.
|
|
|
|
let spinningCb = Async.makeSpinningCallback();
|
|
|
|
|
|
|
|
let livemarkObj = {title: record.title,
|
|
|
|
parentId: record._parent,
|
|
|
|
index: PlacesUtils.bookmarks.DEFAULT_INDEX,
|
|
|
|
feedURI: Utils.makeURI(record.feedUri),
|
|
|
|
siteURI: siteURI,
|
|
|
|
guid: record.id};
|
2014-03-12 15:24:23 +00:00
|
|
|
PlacesUtils.livemarks.addLivemark(livemarkObj).then(
|
|
|
|
aLivemark => { spinningCb(null, [Components.results.NS_OK, aLivemark]) },
|
|
|
|
() => { spinningCb(null, [Components.results.NS_ERROR_UNEXPECTED, aLivemark]) }
|
|
|
|
);
|
2012-02-24 12:42:32 +00:00
|
|
|
|
|
|
|
let [status, livemark] = spinningCb.wait();
|
|
|
|
if (!Components.isSuccessCode(status)) {
|
|
|
|
throw status;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._log.debug("Created livemark " + livemark.id + " under " +
|
|
|
|
livemark.parentId + " as " + livemark.title +
|
|
|
|
", " + livemark.siteURI.spec + ", " +
|
|
|
|
livemark.feedURI.spec + ", GUID " +
|
|
|
|
livemark.guid);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
|
|
|
case "separator":
|
2011-05-20 01:08:22 +00:00
|
|
|
newId = PlacesUtils.bookmarks.insertSeparator(
|
|
|
|
record._parent, PlacesUtils.bookmarks.DEFAULT_INDEX);
|
2011-03-02 23:27:16 +00:00
|
|
|
this._log.debug("created separator " + newId + " under " + record._parent);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
2009-07-10 00:15:00 +00:00
|
|
|
case "item":
|
|
|
|
this._log.debug(" -> got a generic places item.. do nothing?");
|
2009-08-15 08:04:06 +00:00
|
|
|
return;
|
2008-06-03 19:38:48 +00:00
|
|
|
default:
|
2009-04-13 21:39:29 +00:00
|
|
|
this._log.error("_create: Unknown item type: " + record.type);
|
2009-08-15 08:04:06 +00:00
|
|
|
return;
|
2008-12-05 08:39:54 +00:00
|
|
|
}
|
2009-08-15 08:04:06 +00:00
|
|
|
|
2012-02-24 12:42:32 +00:00
|
|
|
if (newId) {
|
|
|
|
// Livemarks can set the GUID through the API, so there's no need to
|
|
|
|
// do that here.
|
|
|
|
this._log.trace("Setting GUID of new item " + newId + " to " + record.id);
|
|
|
|
this._setGUID(newId, record.id);
|
|
|
|
}
|
2008-06-03 19:38:48 +00:00
|
|
|
},
|
|
|
|
|
2011-02-23 20:14:11 +00:00
|
|
|
// Factored out of `remove` to avoid redundant DB queries when the Places ID
|
|
|
|
// is already known.
|
|
|
|
removeById: function removeById(itemId, guid) {
|
2011-05-20 01:08:22 +00:00
|
|
|
let type = PlacesUtils.bookmarks.getItemType(itemId);
|
2008-06-03 19:38:48 +00:00
|
|
|
|
|
|
|
switch (type) {
|
2011-05-20 01:08:22 +00:00
|
|
|
case PlacesUtils.bookmarks.TYPE_BOOKMARK:
|
2011-02-23 20:14:11 +00:00
|
|
|
this._log.debug(" -> removing bookmark " + guid);
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.removeItem(itemId);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
2011-05-20 01:08:22 +00:00
|
|
|
case PlacesUtils.bookmarks.TYPE_FOLDER:
|
2011-02-23 20:14:11 +00:00
|
|
|
this._log.debug(" -> removing folder " + guid);
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.removeItem(itemId);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
2011-05-20 01:08:22 +00:00
|
|
|
case PlacesUtils.bookmarks.TYPE_SEPARATOR:
|
2011-02-23 20:14:11 +00:00
|
|
|
this._log.debug(" -> removing separator " + guid);
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.removeItem(itemId);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-12-17 01:06:45 +00:00
|
|
|
this._log.error("remove: Unknown item type: " + type);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-02-23 20:14:11 +00:00
|
|
|
remove: function BStore_remove(record) {
|
2012-12-05 00:49:55 +00:00
|
|
|
if (kSpecialIds.isSpecialGUID(record.id)) {
|
|
|
|
this._log.warn("Refusing to remove special folder " + record.id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-23 20:14:11 +00:00
|
|
|
let itemId = this.idForGUID(record.id);
|
|
|
|
if (itemId <= 0) {
|
|
|
|
this._log.debug("Item " + record.id + " already removed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.removeById(itemId, record.id);
|
|
|
|
},
|
|
|
|
|
2012-03-28 05:21:22 +00:00
|
|
|
_taggableTypes: ["bookmark", "microsummary", "query"],
|
|
|
|
isTaggable: function isTaggable(recordType) {
|
|
|
|
return this._taggableTypes.indexOf(recordType) != -1;
|
|
|
|
},
|
|
|
|
|
2008-12-17 01:06:45 +00:00
|
|
|
update: function BStore_update(record) {
|
2010-12-06 23:51:38 +00:00
|
|
|
let itemId = this.idForGUID(record.id);
|
2008-12-17 01:06:45 +00:00
|
|
|
|
2009-01-06 21:54:18 +00:00
|
|
|
if (itemId <= 0) {
|
2008-12-23 19:30:31 +00:00
|
|
|
this._log.debug("Skipping update for unknown item: " + record.id);
|
2008-06-03 19:38:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-23 20:14:11 +00:00
|
|
|
// Two items are the same type if they have the same ItemType in Places,
|
|
|
|
// and also share some key characteristics (e.g., both being livemarks).
|
|
|
|
// We figure this out by examining the item to find the equivalent granular
|
|
|
|
// (string) type.
|
|
|
|
// If they're not the same type, we can't just update attributes. Delete
|
|
|
|
// then recreate the record instead.
|
|
|
|
let localItemType = this._recordType(itemId);
|
|
|
|
let remoteRecordType = record.type;
|
|
|
|
this._log.trace("Local type: " + localItemType + ". " +
|
|
|
|
"Remote type: " + remoteRecordType + ".");
|
|
|
|
|
|
|
|
if (localItemType != remoteRecordType) {
|
|
|
|
this._log.debug("Local record and remote record differ in type. " +
|
|
|
|
"Deleting and recreating.");
|
|
|
|
this.removeById(itemId, record.id);
|
|
|
|
this.create(record);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-23 19:30:31 +00:00
|
|
|
this._log.trace("Updating " + record.id + " (" + itemId + ")");
|
|
|
|
|
2010-12-06 23:51:56 +00:00
|
|
|
// Move the bookmark to a new parent or new position if necessary
|
2011-01-14 21:41:09 +00:00
|
|
|
if (record._parent > 0 &&
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.getFolderIdForItem(itemId) != record._parent) {
|
2011-01-14 21:41:09 +00:00
|
|
|
this._reparentItem(itemId, record._parent);
|
2008-12-23 19:30:31 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 21:18:11 +00:00
|
|
|
for (let [key, val] in Iterator(record.cleartext)) {
|
2008-06-03 19:38:48 +00:00
|
|
|
switch (key) {
|
|
|
|
case "title":
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.setItemTitle(itemId, val);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
2009-04-13 21:39:29 +00:00
|
|
|
case "bmkUri":
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.changeBookmarkURI(itemId, Utils.makeURI(val));
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
2009-07-13 20:40:49 +00:00
|
|
|
case "tags":
|
2012-03-28 05:21:22 +00:00
|
|
|
if (Array.isArray(val)) {
|
|
|
|
if (this.isTaggable(remoteRecordType)) {
|
|
|
|
this._tagID(itemId, val);
|
|
|
|
} else {
|
|
|
|
this._log.debug("Remote record type is invalid for tags: " + remoteRecordType);
|
|
|
|
}
|
2011-01-14 21:41:09 +00:00
|
|
|
}
|
2009-07-13 20:40:49 +00:00
|
|
|
break;
|
2008-06-03 19:38:48 +00:00
|
|
|
case "keyword":
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.setKeywordForBookmark(itemId, val);
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
|
|
|
case "description":
|
2011-05-17 20:53:23 +00:00
|
|
|
if (val) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
itemId, DESCRIPTION_ANNO, val, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-05-17 20:53:23 +00:00
|
|
|
} else {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.removeItemAnnotation(itemId, DESCRIPTION_ANNO);
|
2011-05-17 20:53:23 +00:00
|
|
|
}
|
2008-06-03 19:38:48 +00:00
|
|
|
break;
|
2009-06-16 23:16:39 +00:00
|
|
|
case "loadInSidebar":
|
2011-03-02 23:27:16 +00:00
|
|
|
if (val) {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
itemId, SIDEBAR_ANNO, true, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-03-02 23:27:16 +00:00
|
|
|
} else {
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.removeItemAnnotation(itemId, SIDEBAR_ANNO);
|
2011-03-02 23:27:16 +00:00
|
|
|
}
|
2009-06-16 23:16:39 +00:00
|
|
|
break;
|
2011-01-26 20:36:38 +00:00
|
|
|
case "queryId":
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.setItemAnnotation(
|
|
|
|
itemId, SMART_BOOKMARKS_ANNO, val, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2011-01-26 20:36:38 +00:00
|
|
|
break;
|
2008-06-03 19:38:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-12-06 23:51:56 +00: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;
|
2011-02-16 23:53:23 +00:00
|
|
|
let parent = null;
|
2010-12-06 23:51:56 +00:00
|
|
|
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 {
|
2011-02-16 23:53:23 +00:00
|
|
|
// This code path could be optimized by caching the parent earlier.
|
|
|
|
// Doing so should take in count any edge case due to reparenting
|
|
|
|
// or parent invalidations though.
|
2011-05-20 01:08:22 +00:00
|
|
|
if (!parent) {
|
|
|
|
parent = PlacesUtils.bookmarks.getFolderIdForItem(itemid);
|
|
|
|
}
|
|
|
|
PlacesUtils.bookmarks.moveItem(itemid, parent, idx - delta);
|
2010-12-06 23:51:56 +00:00
|
|
|
} catch (ex) {
|
|
|
|
this._log.debug("Could not move item " + children[idx] + ": " + ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2008-12-08 21:21:25 +00:00
|
|
|
changeItemID: function BStore_changeItemID(oldID, newID) {
|
2010-12-08 05:49:22 +00:00
|
|
|
this._log.debug("Changing GUID " + oldID + " to " + newID);
|
2009-09-09 06:33:15 +00:00
|
|
|
|
|
|
|
// Make sure there's an item to change GUIDs
|
2010-12-06 23:51:38 +00:00
|
|
|
let itemId = this.idForGUID(oldID);
|
2009-09-09 06:33:15 +00:00
|
|
|
if (itemId <= 0)
|
2008-12-05 08:39:54 +00:00
|
|
|
return;
|
2008-11-26 15:25:28 +00:00
|
|
|
|
2009-08-15 08:04:06 +00:00
|
|
|
this._setGUID(itemId, newID);
|
|
|
|
},
|
|
|
|
|
2008-12-29 03:59:44 +00:00
|
|
|
_getNode: function BStore__getNode(folder) {
|
2011-05-20 01:08:22 +00:00
|
|
|
let query = PlacesUtils.history.getNewQuery();
|
2008-06-03 19:38:48 +00:00
|
|
|
query.setFolders([folder], 1);
|
2011-05-20 01:08:22 +00:00
|
|
|
return PlacesUtils.history.executeQuery(
|
|
|
|
query, PlacesUtils.history.getNewQueryOptions()).root;
|
2008-06-03 19:38:48 +00:00
|
|
|
},
|
|
|
|
|
2008-12-29 03:59:44 +00: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 19:38:48 +00:00
|
|
|
}
|
2011-05-20 01:08:22 +00:00
|
|
|
return PlacesUtils.tagging.getTagsForURI(uri, {});
|
2008-12-29 03:59:44 +00:00
|
|
|
},
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2008-12-29 03:59:44 +00:00
|
|
|
_getDescription: function BStore__getDescription(id) {
|
|
|
|
try {
|
2011-05-20 01:08:22 +00:00
|
|
|
return PlacesUtils.annotations.getItemAnnotation(id, DESCRIPTION_ANNO);
|
2008-12-29 03:59:44 +00:00
|
|
|
} catch (e) {
|
2011-01-14 21:41:09 +00:00
|
|
|
return null;
|
2008-12-29 03:59:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-06-16 23:16:39 +00:00
|
|
|
_isLoadInSidebar: function BStore__isLoadInSidebar(id) {
|
2011-05-20 01:08:22 +00:00
|
|
|
return PlacesUtils.annotations.itemHasAnnotation(id, SIDEBAR_ANNO);
|
2009-06-16 23:16:39 +00:00
|
|
|
},
|
|
|
|
|
2011-01-13 22:03:11 +00:00
|
|
|
get _childGUIDsStm() {
|
2011-04-07 22:30:31 +00:00
|
|
|
return this._getStmt(
|
|
|
|
"SELECT id AS item_id, guid " +
|
|
|
|
"FROM moz_bookmarks " +
|
|
|
|
"WHERE parent = :parent " +
|
|
|
|
"ORDER BY position");
|
2011-01-13 22:03:11 +00:00
|
|
|
},
|
2011-03-01 22:29:52 +00:00
|
|
|
_childGUIDsCols: ["item_id", "guid"],
|
2011-01-13 22:03:11 +00:00
|
|
|
|
|
|
|
_getChildGUIDsForId: function _getChildGUIDsForId(itemid) {
|
|
|
|
let stmt = this._childGUIDsStm;
|
|
|
|
stmt.params.parent = itemid;
|
2011-05-31 01:52:23 +00:00
|
|
|
let rows = Async.querySpinningly(stmt, this._childGUIDsCols);
|
2011-01-13 22:03:11 +00:00
|
|
|
return rows.map(function (row) {
|
|
|
|
if (row.guid) {
|
|
|
|
return row.guid;
|
|
|
|
}
|
|
|
|
// A GUID hasn't been assigned to this item yet, do this now.
|
|
|
|
return this.GUIDForId(row.item_id);
|
|
|
|
}, this);
|
2010-12-06 23:51:56 +00:00
|
|
|
},
|
|
|
|
|
2008-12-29 03:59:44 +00:00
|
|
|
// Create a record starting from the weave id (places guid)
|
2010-11-30 00:41:17 +00:00
|
|
|
createRecord: function createRecord(id, collection) {
|
2010-12-06 23:51:38 +00:00
|
|
|
let placeId = this.idForGUID(id);
|
2010-03-25 20:58:27 +00:00
|
|
|
let record;
|
2009-01-06 21:54:18 +00:00
|
|
|
if (placeId <= 0) { // deleted item
|
2010-11-30 00:41:17 +00:00
|
|
|
record = new PlacesItem(collection, id);
|
2009-04-03 17:38:47 +00:00
|
|
|
record.deleted = true;
|
2008-12-29 03:59:44 +00:00
|
|
|
return record;
|
|
|
|
}
|
|
|
|
|
2011-05-20 01:08:22 +00:00
|
|
|
let parent = PlacesUtils.bookmarks.getFolderIdForItem(placeId);
|
|
|
|
switch (PlacesUtils.bookmarks.getItemType(placeId)) {
|
|
|
|
case PlacesUtils.bookmarks.TYPE_BOOKMARK:
|
|
|
|
let bmkUri = PlacesUtils.bookmarks.getBookmarkURI(placeId).spec;
|
2012-02-24 12:42:32 +00:00
|
|
|
if (bmkUri.indexOf("place:") == 0) {
|
2011-04-26 12:25:27 +00:00
|
|
|
record = new BookmarkQuery(collection, id);
|
|
|
|
|
|
|
|
// 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];
|
2011-05-20 01:08:22 +00:00
|
|
|
record.folderName = PlacesUtils.bookmarks.getItemTitle(folder);
|
2011-04-26 12:25:27 +00:00
|
|
|
this._log.trace("query id: " + folder + " = " + record.folderName);
|
2011-01-26 20:36:38 +00:00
|
|
|
}
|
2011-04-26 12:25:27 +00:00
|
|
|
}
|
|
|
|
catch(ex) {}
|
|
|
|
|
|
|
|
// Persist the Smart Bookmark anno, if found.
|
|
|
|
try {
|
2011-05-20 01:08:22 +00:00
|
|
|
let anno = PlacesUtils.annotations.getItemAnnotation(placeId, SMART_BOOKMARKS_ANNO);
|
2011-04-26 12:25:27 +00:00
|
|
|
if (anno != null) {
|
|
|
|
this._log.trace("query anno: " + SMART_BOOKMARKS_ANNO +
|
|
|
|
" = " + anno);
|
|
|
|
record.queryId = anno;
|
2009-07-14 00:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-26 12:25:27 +00:00
|
|
|
catch(ex) {}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
record = new Bookmark(collection, id);
|
2008-06-03 19:38:48 +00:00
|
|
|
}
|
2011-05-20 01:08:22 +00:00
|
|
|
record.title = PlacesUtils.bookmarks.getItemTitle(placeId);
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2011-05-20 01:08:22 +00:00
|
|
|
record.parentName = PlacesUtils.bookmarks.getItemTitle(parent);
|
2009-07-14 00:43:15 +00:00
|
|
|
record.bmkUri = bmkUri;
|
2008-12-29 03:59:44 +00:00
|
|
|
record.tags = this._getTags(record.bmkUri);
|
2011-05-20 01:08:22 +00:00
|
|
|
record.keyword = PlacesUtils.bookmarks.getKeywordForBookmark(placeId);
|
2008-12-29 03:59:44 +00:00
|
|
|
record.description = this._getDescription(placeId);
|
2009-06-16 23:16:39 +00:00
|
|
|
record.loadInSidebar = this._isLoadInSidebar(placeId);
|
2008-12-29 03:59:44 +00:00
|
|
|
break;
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2011-05-20 01:08:22 +00:00
|
|
|
case PlacesUtils.bookmarks.TYPE_FOLDER:
|
2012-02-24 12:42:32 +00:00
|
|
|
if (PlacesUtils.annotations
|
|
|
|
.itemHasAnnotation(placeId, PlacesUtils.LMANNO_FEEDURI)) {
|
2010-11-30 00:41:17 +00:00
|
|
|
record = new Livemark(collection, id);
|
2012-02-24 12:42:32 +00:00
|
|
|
let as = PlacesUtils.annotations;
|
|
|
|
record.feedUri = as.getItemAnnotation(placeId, PlacesUtils.LMANNO_FEEDURI);
|
|
|
|
try {
|
|
|
|
record.siteUri = as.getItemAnnotation(placeId, PlacesUtils.LMANNO_SITEURI);
|
|
|
|
} catch (ex) {}
|
2008-12-29 03:59:44 +00:00
|
|
|
} else {
|
2010-11-30 00:41:17 +00:00
|
|
|
record = new BookmarkFolder(collection, id);
|
2008-06-04 20:40:53 +00:00
|
|
|
}
|
2009-04-01 22:12:08 +00:00
|
|
|
|
2010-12-06 23:51:56 +00:00
|
|
|
if (parent > 0)
|
2011-05-20 01:08:22 +00:00
|
|
|
record.parentName = PlacesUtils.bookmarks.getItemTitle(parent);
|
|
|
|
record.title = PlacesUtils.bookmarks.getItemTitle(placeId);
|
2010-04-01 22:11:42 +00:00
|
|
|
record.description = this._getDescription(placeId);
|
2010-12-06 23:51:56 +00:00
|
|
|
record.children = this._getChildGUIDsForId(placeId);
|
2008-12-29 03:59:44 +00:00
|
|
|
break;
|
2008-06-04 20:40:53 +00:00
|
|
|
|
2011-05-20 01:08:22 +00:00
|
|
|
case PlacesUtils.bookmarks.TYPE_SEPARATOR:
|
2010-11-30 00:41:17 +00:00
|
|
|
record = new BookmarkSeparator(collection, id);
|
2010-12-06 23:51:56 +00:00
|
|
|
if (parent > 0)
|
2011-05-20 01:08:22 +00:00
|
|
|
record.parentName = PlacesUtils.bookmarks.getItemTitle(parent);
|
2011-06-15 07:03:34 +00:00
|
|
|
// Create a positioning identifier for the separator, used by _mapDupe
|
2011-05-20 01:08:22 +00:00
|
|
|
record.pos = PlacesUtils.bookmarks.getItemIndex(placeId);
|
2008-12-29 03:59:44 +00:00
|
|
|
break;
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2008-12-29 03:59:44 +00:00
|
|
|
default:
|
2010-11-30 00:41:17 +00:00
|
|
|
record = new PlacesItem(collection, id);
|
2008-12-29 03:59:44 +00:00
|
|
|
this._log.warn("Unknown item type, cannot serialize: " +
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.getItemType(placeId));
|
2008-06-03 19:38:48 +00:00
|
|
|
}
|
|
|
|
|
2010-12-06 23:51:56 +00:00
|
|
|
record.parentid = this.GUIDForId(parent);
|
2009-10-16 23:19:28 +00:00
|
|
|
record.sortindex = this._calculateIndex(record);
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2008-12-29 03:59:44 +00:00
|
|
|
return record;
|
2008-06-03 19:38:48 +00:00
|
|
|
},
|
|
|
|
|
2010-12-06 23:51:38 +00:00
|
|
|
_stmts: {},
|
|
|
|
_getStmt: function(query) {
|
2011-08-27 02:14:09 +00:00
|
|
|
if (query in this._stmts) {
|
2010-12-06 23:51:38 +00:00
|
|
|
return this._stmts[query];
|
2011-08-27 02:14:09 +00:00
|
|
|
}
|
2010-12-06 23:51:38 +00:00
|
|
|
|
|
|
|
this._log.trace("Creating SQL statement: " + query);
|
2011-05-20 01:08:22 +00:00
|
|
|
let db = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase)
|
|
|
|
.DBConnection;
|
|
|
|
return this._stmts[query] = db.createAsyncStatement(query);
|
2010-12-16 00:08:04 +00:00
|
|
|
},
|
|
|
|
|
2009-10-16 23:19:28 +00:00
|
|
|
get _frecencyStm() {
|
2010-12-06 23:51:38 +00:00
|
|
|
return this._getStmt(
|
2010-08-04 12:50:44 +00:00
|
|
|
"SELECT frecency " +
|
|
|
|
"FROM moz_places " +
|
2010-08-09 16:38:18 +00:00
|
|
|
"WHERE url = :url " +
|
|
|
|
"LIMIT 1");
|
2010-12-06 23:51:38 +00:00
|
|
|
},
|
2011-03-01 22:29:52 +00:00
|
|
|
_frecencyCols: ["frecency"],
|
2010-12-06 23:51:38 +00:00
|
|
|
|
2010-12-14 23:48:05 +00:00
|
|
|
get _setGUIDStm() {
|
2011-04-07 22:30:31 +00:00
|
|
|
return this._getStmt(
|
|
|
|
"UPDATE moz_bookmarks " +
|
|
|
|
"SET guid = :guid " +
|
|
|
|
"WHERE id = :item_id");
|
2010-12-14 23:48:05 +00:00
|
|
|
},
|
|
|
|
|
2010-12-06 23:51:38 +00:00
|
|
|
// Some helper functions to handle GUIDs
|
|
|
|
_setGUID: function _setGUID(id, guid) {
|
2011-03-02 23:27:16 +00:00
|
|
|
if (!guid)
|
2010-12-06 23:51:38 +00:00
|
|
|
guid = Utils.makeGUID();
|
|
|
|
|
2011-04-07 22:30:31 +00:00
|
|
|
let stmt = this._setGUIDStm;
|
|
|
|
stmt.params.guid = guid;
|
2010-12-06 23:51:38 +00:00
|
|
|
stmt.params.item_id = id;
|
2011-05-31 01:52:23 +00:00
|
|
|
Async.querySpinningly(stmt);
|
2010-12-06 23:51:38 +00:00
|
|
|
return guid;
|
|
|
|
},
|
|
|
|
|
|
|
|
get _guidForIdStm() {
|
2011-04-07 22:30:31 +00:00
|
|
|
return this._getStmt(
|
|
|
|
"SELECT guid " +
|
|
|
|
"FROM moz_bookmarks " +
|
|
|
|
"WHERE id = :item_id");
|
2010-12-06 23:51:38 +00:00
|
|
|
},
|
2011-03-01 22:29:52 +00:00
|
|
|
_guidForIdCols: ["guid"],
|
2010-12-06 23:51:38 +00:00
|
|
|
|
|
|
|
GUIDForId: function GUIDForId(id) {
|
2011-01-24 18:45:27 +00:00
|
|
|
let special = kSpecialIds.specialGUIDForId(id);
|
|
|
|
if (special)
|
|
|
|
return special;
|
2010-12-06 23:51:38 +00:00
|
|
|
|
|
|
|
let stmt = this._guidForIdStm;
|
|
|
|
stmt.params.item_id = id;
|
|
|
|
|
|
|
|
// Use the existing GUID if it exists
|
2011-05-31 01:52:23 +00:00
|
|
|
let result = Async.querySpinningly(stmt, this._guidForIdCols)[0];
|
2010-12-14 23:48:05 +00:00
|
|
|
if (result && result.guid)
|
2010-12-06 23:51:38 +00:00
|
|
|
return result.guid;
|
|
|
|
|
|
|
|
// Give the uri a GUID if it doesn't have one
|
|
|
|
return this._setGUID(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
get _idForGUIDStm() {
|
2011-04-07 22:30:31 +00:00
|
|
|
return this._getStmt(
|
|
|
|
"SELECT id AS item_id " +
|
|
|
|
"FROM moz_bookmarks " +
|
|
|
|
"WHERE guid = :guid");
|
2010-12-06 23:51:38 +00:00
|
|
|
},
|
2011-03-01 22:29:52 +00:00
|
|
|
_idForGUIDCols: ["item_id"],
|
2010-12-06 23:51:38 +00:00
|
|
|
|
2011-01-24 18:45:27 +00:00
|
|
|
// noCreate is provided as an optional argument to prevent the creation of
|
|
|
|
// non-existent special records, such as "mobile".
|
|
|
|
idForGUID: function idForGUID(guid, noCreate) {
|
|
|
|
if (kSpecialIds.isSpecialGUID(guid))
|
|
|
|
return kSpecialIds.specialIdForGUID(guid, !noCreate);
|
2010-12-06 23:51:38 +00:00
|
|
|
|
|
|
|
let stmt = this._idForGUIDStm;
|
|
|
|
// guid might be a String object rather than a string.
|
|
|
|
stmt.params.guid = guid.toString();
|
|
|
|
|
2011-05-31 01:52:23 +00:00
|
|
|
let results = Async.querySpinningly(stmt, this._idForGUIDCols);
|
2011-03-02 23:27:16 +00:00
|
|
|
this._log.trace("Number of rows matching GUID " + guid + ": "
|
|
|
|
+ results.length);
|
2011-01-25 20:37:23 +00:00
|
|
|
|
|
|
|
// Here's the one we care about: the first.
|
|
|
|
let result = results[0];
|
|
|
|
|
|
|
|
if (!result)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return result.item_id;
|
2009-10-16 23:19:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_calculateIndex: function _calculateIndex(record) {
|
2010-11-09 21:53:50 +00: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 23:19:28 +00: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;
|
|
|
|
|
2011-08-20 00:17:58 +00:00
|
|
|
// Add in the bookmark's frecency if we have something.
|
2009-10-16 23:19:28 +00:00
|
|
|
if (record.bmkUri != null) {
|
2010-08-09 16:38:18 +00:00
|
|
|
this._frecencyStm.params.url = record.bmkUri;
|
2011-05-31 01:52:23 +00:00
|
|
|
let result = Async.querySpinningly(this._frecencyStm, this._frecencyCols);
|
2010-08-09 16:38:18 +00:00
|
|
|
if (result.length)
|
2010-08-09 23:59:26 +00:00
|
|
|
index += result[0].frecency;
|
2009-10-16 23:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
|
2009-08-14 01:50:54 +00:00
|
|
|
_getChildren: function BStore_getChildren(guid, items) {
|
2009-01-03 05:13:32 +00:00
|
|
|
let node = guid; // the recursion case
|
2011-01-24 18:45:27 +00:00
|
|
|
if (typeof(node) == "string") { // callers will give us the guid as the first arg
|
|
|
|
let nodeID = this.idForGUID(guid, true);
|
|
|
|
if (!nodeID) {
|
|
|
|
this._log.debug("No node for GUID " + guid + "; returning no children.");
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
node = this._getNode(nodeID);
|
|
|
|
}
|
|
|
|
|
2012-02-24 12:42:32 +00:00
|
|
|
if (node.type == node.RESULT_TYPE_FOLDER) {
|
2008-12-29 03:59:44 +00:00
|
|
|
node.QueryInterface(Ci.nsINavHistoryQueryResultNode);
|
|
|
|
node.containerOpen = true;
|
2011-04-23 00:08:36 +00:00
|
|
|
try {
|
|
|
|
// Remember all the children GUIDs and recursively get more
|
|
|
|
for (let i = 0; i < node.childCount; i++) {
|
|
|
|
let child = node.getChild(i);
|
|
|
|
items[this.GUIDForId(child.itemId)] = true;
|
|
|
|
this._getChildren(child, items);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
node.containerOpen = false;
|
2008-12-29 03:59:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-08 17:53:32 +00:00
|
|
|
|
2008-12-29 03:59:44 +00:00
|
|
|
return items;
|
2008-12-08 17:53:32 +00:00
|
|
|
},
|
|
|
|
|
2012-03-27 01:40:28 +00:00
|
|
|
/**
|
|
|
|
* Associates the URI of the item with the provided ID with the
|
|
|
|
* provided array of tags.
|
|
|
|
* If the provided ID does not identify an item with a URI,
|
|
|
|
* returns immediately.
|
|
|
|
*/
|
|
|
|
_tagID: function _tagID(itemID, tags) {
|
|
|
|
if (!itemID || !tags) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2012-03-28 05:21:22 +00:00
|
|
|
let u = PlacesUtils.bookmarks.getBookmarkURI(itemID);
|
|
|
|
this._tagURI(u, tags);
|
2012-03-27 01:40:28 +00:00
|
|
|
} catch (e) {
|
2012-03-28 05:21:22 +00:00
|
|
|
this._log.warn("Got exception fetching URI for " + itemID + ": not tagging. " +
|
|
|
|
Utils.exceptionStr(e));
|
|
|
|
|
2012-03-27 01:40:28 +00:00
|
|
|
// I guess it doesn't have a URI. Don't try to tag it.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Associate the provided URI with the provided array of tags.
|
|
|
|
* If the provided URI is falsy, returns immediately.
|
|
|
|
*/
|
|
|
|
_tagURI: function _tagURI(bookmarkURI, tags) {
|
|
|
|
if (!bookmarkURI || !tags) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-20 00:17:58 +00:00
|
|
|
// Filter out any null/undefined/empty tags.
|
2009-07-13 20:40:49 +00:00
|
|
|
tags = tags.filter(function(t) t);
|
|
|
|
|
2011-08-20 00:17:58 +00:00
|
|
|
// Temporarily tag a dummy URI to preserve tag ids when untagging.
|
2009-07-14 00:43:15 +00:00
|
|
|
let dummyURI = Utils.makeURI("about:weave#BStore_tagURI");
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.tagging.tagURI(dummyURI, tags);
|
2012-03-27 01:40:28 +00:00
|
|
|
PlacesUtils.tagging.untagURI(bookmarkURI, null);
|
|
|
|
PlacesUtils.tagging.tagURI(bookmarkURI, tags);
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.tagging.untagURI(dummyURI, null);
|
2009-07-13 20:40:49 +00:00
|
|
|
},
|
2009-01-03 05:13:32 +00:00
|
|
|
|
|
|
|
getAllIDs: function BStore_getAllIDs() {
|
2010-12-06 23:51:56 +00:00
|
|
|
let items = {"menu": true,
|
|
|
|
"toolbar": true};
|
2011-01-24 18:45:27 +00:00
|
|
|
for each (let guid in kSpecialIds.guids) {
|
2009-08-15 07:59:49 +00:00
|
|
|
if (guid != "places" && guid != "tags")
|
|
|
|
this._getChildren(guid, items);
|
2011-01-24 18:45:27 +00:00
|
|
|
}
|
2009-01-02 21:49:19 +00:00
|
|
|
return items;
|
|
|
|
},
|
|
|
|
|
2008-06-03 19:38:48 +00:00
|
|
|
wipe: function BStore_wipe() {
|
2013-04-09 09:15:34 +00:00
|
|
|
let cb = Async.makeSpinningCallback();
|
|
|
|
Task.spawn(function() {
|
|
|
|
// Save a backup before clearing out all bookmarks.
|
2013-04-26 02:09:52 +00:00
|
|
|
yield PlacesBackups.create(null, true);
|
2013-04-09 09:15:34 +00:00
|
|
|
for each (let guid in kSpecialIds.guids)
|
|
|
|
if (guid != "places") {
|
|
|
|
let id = kSpecialIds.specialIdForGUID(guid);
|
|
|
|
if (id)
|
|
|
|
PlacesUtils.bookmarks.removeFolderChildren(id);
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
});
|
|
|
|
cb.wait();
|
2008-06-03 19:38:48 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-29 21:43:41 +00:00
|
|
|
function BookmarksTracker(name, engine) {
|
|
|
|
Tracker.call(this, name, engine);
|
2010-02-11 23:25:31 +00:00
|
|
|
|
2010-08-06 15:30:58 +00:00
|
|
|
Svc.Obs.add("places-shutdown", this);
|
2008-06-03 19:38:48 +00:00
|
|
|
}
|
|
|
|
BookmarksTracker.prototype = {
|
2008-11-07 03:18:46 +00:00
|
|
|
__proto__: Tracker.prototype,
|
2008-12-05 08:39:54 +00:00
|
|
|
|
2013-12-19 05:42:17 +00:00
|
|
|
startTracking: function() {
|
|
|
|
PlacesUtils.bookmarks.addObserver(this, true);
|
|
|
|
Svc.Obs.add("bookmarks-restore-begin", this);
|
|
|
|
Svc.Obs.add("bookmarks-restore-success", this);
|
|
|
|
Svc.Obs.add("bookmarks-restore-failed", this);
|
|
|
|
},
|
|
|
|
|
|
|
|
stopTracking: function() {
|
|
|
|
PlacesUtils.bookmarks.removeObserver(this);
|
|
|
|
Svc.Obs.remove("bookmarks-restore-begin", this);
|
|
|
|
Svc.Obs.remove("bookmarks-restore-success", this);
|
|
|
|
Svc.Obs.remove("bookmarks-restore-failed", this);
|
|
|
|
},
|
|
|
|
|
2010-08-06 15:30:58 +00:00
|
|
|
observe: function observe(subject, topic, data) {
|
2013-12-19 05:42:17 +00:00
|
|
|
Tracker.prototype.observe.call(this, subject, topic, data);
|
2012-09-14 23:02:33 +00:00
|
|
|
|
2013-12-19 05:42:17 +00:00
|
|
|
switch (topic) {
|
2011-01-25 07:06:42 +00:00
|
|
|
case "bookmarks-restore-begin":
|
|
|
|
this._log.debug("Ignoring changes from importing bookmarks.");
|
|
|
|
this.ignoreAll = true;
|
|
|
|
break;
|
|
|
|
case "bookmarks-restore-success":
|
|
|
|
this._log.debug("Tracking all items on successful import.");
|
|
|
|
this.ignoreAll = false;
|
2012-09-14 23:02:33 +00:00
|
|
|
|
2011-01-25 07:06:42 +00:00
|
|
|
this._log.debug("Restore succeeded: wiping server and other clients.");
|
2012-09-14 23:02:33 +00:00
|
|
|
this.engine.service.resetClient([this.name]);
|
|
|
|
this.engine.service.wipeServer([this.name]);
|
2012-08-29 21:43:41 +00:00
|
|
|
this.engine.service.clientsEngine.sendCommand("wipeEngine", [this.name]);
|
2011-01-25 07:06:42 +00:00
|
|
|
break;
|
|
|
|
case "bookmarks-restore-failed":
|
|
|
|
this._log.debug("Tracking all items on failed import.");
|
|
|
|
this.ignoreAll = false;
|
|
|
|
break;
|
2010-08-06 15:30:58 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-06-17 15:51:54 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([
|
|
|
|
Ci.nsINavBookmarkObserver,
|
2010-08-04 19:07:53 +00:00
|
|
|
Ci.nsINavBookmarkObserver_MOZILLA_1_9_1_ADDITIONS,
|
|
|
|
Ci.nsISupportsWeakReference
|
2009-06-17 15:51:54 +00:00
|
|
|
]),
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2009-06-17 15:51:54 +00:00
|
|
|
/**
|
2011-08-20 00:17:58 +00:00
|
|
|
* Add a bookmark GUID to be uploaded and bump up the sync score.
|
2009-06-17 15:51:54 +00:00
|
|
|
*
|
2011-05-17 20:53:23 +00:00
|
|
|
* @param itemGuid
|
2011-08-20 00:17:58 +00:00
|
|
|
* GUID of the bookmark to upload.
|
2009-06-17 15:51:54 +00:00
|
|
|
*/
|
2011-05-18 21:27:39 +00:00
|
|
|
_add: function BMT__add(itemId, guid) {
|
|
|
|
guid = kSpecialIds.specialGUIDForId(itemId) || guid;
|
|
|
|
if (this.addChangedID(guid))
|
2009-06-17 15:51:54 +00:00
|
|
|
this._upScore();
|
|
|
|
},
|
|
|
|
|
2011-08-20 00:17:58 +00:00
|
|
|
/* Every add/remove/change will trigger a sync for MULTI_DEVICE. */
|
2008-12-06 08:12:40 +00:00
|
|
|
_upScore: function BMT__upScore() {
|
2011-06-16 19:12:48 +00:00
|
|
|
this.score += SCORE_INCREMENT_XLARGE;
|
2008-06-03 19:38:48 +00:00
|
|
|
},
|
2008-11-20 00:21:12 +00:00
|
|
|
|
2009-04-08 03:56:04 +00:00
|
|
|
/**
|
2012-02-24 12:42:32 +00:00
|
|
|
* Determine if a change should be ignored.
|
2009-04-08 03:56:04 +00:00
|
|
|
*
|
2009-06-17 15:51:54 +00:00
|
|
|
* @param itemId
|
|
|
|
* Item under consideration to ignore
|
|
|
|
* @param folder (optional)
|
2009-04-08 03:56:04 +00:00
|
|
|
* Folder of the item being changed
|
|
|
|
*/
|
2011-05-17 20:53:23 +00:00
|
|
|
_ignore: function BMT__ignore(itemId, folder, guid) {
|
2011-04-07 22:55:29 +00:00
|
|
|
// Ignore unconditionally if the engine tells us to.
|
2009-04-08 03:56:04 +00:00
|
|
|
if (this.ignoreAll)
|
|
|
|
return true;
|
|
|
|
|
2011-04-07 22:55:29 +00:00
|
|
|
// Get the folder id if we weren't given one.
|
|
|
|
if (folder == null) {
|
|
|
|
try {
|
2011-05-20 01:08:22 +00:00
|
|
|
folder = PlacesUtils.bookmarks.getFolderIdForItem(itemId);
|
2011-04-07 22:55:29 +00:00
|
|
|
} catch (ex) {
|
|
|
|
this._log.debug("getFolderIdForItem(" + itemId +
|
|
|
|
") threw; calling _ensureMobileQuery.");
|
|
|
|
// I'm guessing that gFIFI can throw, and perhaps that's why
|
|
|
|
// _ensureMobileQuery is here at all. Try not to call it.
|
|
|
|
this._ensureMobileQuery();
|
2011-05-20 01:08:22 +00:00
|
|
|
folder = PlacesUtils.bookmarks.getFolderIdForItem(itemId);
|
2011-04-07 22:55:29 +00:00
|
|
|
}
|
2009-12-11 00:12:14 +00:00
|
|
|
}
|
|
|
|
|
2011-04-07 22:55:29 +00:00
|
|
|
// Ignore changes to tags (folders under the tags folder).
|
2009-08-15 07:59:49 +00:00
|
|
|
let tags = kSpecialIds.tags;
|
2009-04-08 04:17:40 +00:00
|
|
|
if (folder == tags)
|
|
|
|
return true;
|
|
|
|
|
2011-04-07 22:55:29 +00:00
|
|
|
// Ignore tag items (the actual instance of a tag for a bookmark).
|
2011-05-20 01:08:22 +00:00
|
|
|
if (PlacesUtils.bookmarks.getFolderIdForItem(folder) == tags)
|
2009-04-08 04:17:40 +00:00
|
|
|
return true;
|
|
|
|
|
2011-04-07 22:55:29 +00:00
|
|
|
// Make sure to remove items that have the exclude annotation.
|
2011-05-20 01:08:22 +00:00
|
|
|
if (PlacesUtils.annotations.itemHasAnnotation(itemId, EXCLUDEBACKUP_ANNO)) {
|
2011-05-17 20:53:23 +00:00
|
|
|
this.removeChangedID(guid);
|
2011-04-07 22:55:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2009-04-08 03:56:04 +00:00
|
|
|
},
|
|
|
|
|
2011-05-17 20:53:23 +00:00
|
|
|
onItemAdded: function BMT_onItemAdded(itemId, folder, index,
|
|
|
|
itemType, uri, title, dateAdded,
|
|
|
|
guid, parentGuid) {
|
|
|
|
if (this._ignore(itemId, folder, guid))
|
2009-01-15 21:58:59 +00:00
|
|
|
return;
|
2009-02-02 19:43:06 +00:00
|
|
|
|
2008-12-19 19:48:09 +00:00
|
|
|
this._log.trace("onItemAdded: " + itemId);
|
2011-05-18 21:27:39 +00:00
|
|
|
this._add(itemId, guid);
|
|
|
|
this._add(folder, parentGuid);
|
2008-12-06 08:12:40 +00:00
|
|
|
},
|
|
|
|
|
2013-01-04 17:45:12 +00:00
|
|
|
onItemRemoved: function (itemId, parentId, index, type, uri,
|
|
|
|
guid, parentGuid) {
|
|
|
|
if (this._ignore(itemId, parentId, guid)) {
|
2009-01-15 21:58:59 +00:00
|
|
|
return;
|
2013-01-04 17:45:12 +00:00
|
|
|
}
|
2009-02-02 19:43:06 +00:00
|
|
|
|
2013-01-04 17:45:12 +00:00
|
|
|
this._log.trace("onItemRemoved: " + itemId);
|
2011-05-18 21:27:39 +00:00
|
|
|
this._add(itemId, guid);
|
|
|
|
this._add(parentId, parentGuid);
|
2008-06-03 19:38:48 +00:00
|
|
|
},
|
2008-11-20 00:21:12 +00:00
|
|
|
|
2009-12-11 00:12:14 +00:00
|
|
|
_ensureMobileQuery: function _ensureMobileQuery() {
|
2011-05-17 20:53:23 +00:00
|
|
|
let find = function (val)
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.getItemsWithAnnotation(ORGANIZERQUERY_ANNO, {}).filter(
|
|
|
|
function (id) PlacesUtils.annotations.getItemAnnotation(id, ORGANIZERQUERY_ANNO) == val
|
2011-05-17 20:53:23 +00:00
|
|
|
);
|
2009-02-02 19:43:06 +00:00
|
|
|
|
2009-12-11 00:12:14 +00:00
|
|
|
// Don't continue if the Library isn't ready
|
2011-03-02 23:27:16 +00:00
|
|
|
let all = find(ALLBOOKMARKS_ANNO);
|
2009-12-11 00:12:14 +00:00
|
|
|
if (all.length == 0)
|
2009-08-25 23:15:05 +00:00
|
|
|
return;
|
2009-12-11 00:12:14 +00:00
|
|
|
|
|
|
|
// Disable handling of notifications while changing the mobile query
|
|
|
|
this.ignoreAll = true;
|
|
|
|
|
2011-03-02 23:27:16 +00:00
|
|
|
let mobile = find(MOBILE_ANNO);
|
2009-12-11 00:12:14 +00:00
|
|
|
let queryURI = Utils.makeURI("place:folder=" + kSpecialIds.mobile);
|
|
|
|
let title = Str.sync.get("mobile.label");
|
2009-12-15 22:21:13 +00:00
|
|
|
|
2011-04-07 22:55:29 +00:00
|
|
|
// Don't add OR remove the mobile bookmarks if there's nothing.
|
2011-05-20 01:08:22 +00:00
|
|
|
if (PlacesUtils.bookmarks.getIdForItemAt(kSpecialIds.mobile, 0) == -1) {
|
2009-12-15 22:21:13 +00:00
|
|
|
if (mobile.length != 0)
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.bookmarks.removeItem(mobile[0]);
|
2009-12-15 22:21:13 +00:00
|
|
|
}
|
|
|
|
// Add the mobile bookmarks query if it doesn't exist
|
|
|
|
else if (mobile.length == 0) {
|
2011-05-20 01:08:22 +00:00
|
|
|
let query = PlacesUtils.bookmarks.insertBookmark(all[0], queryURI, -1, title);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(query, ORGANIZERQUERY_ANNO, MOBILE_ANNO, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
|
|
|
PlacesUtils.annotations.setItemAnnotation(query, EXCLUDEBACKUP_ANNO, 1, 0,
|
|
|
|
PlacesUtils.annotations.EXPIRE_NEVER);
|
2009-08-25 23:15:05 +00:00
|
|
|
}
|
2009-12-11 00:12:14 +00:00
|
|
|
// Make sure the existing title is correct
|
2011-05-20 01:08:22 +00:00
|
|
|
else if (PlacesUtils.bookmarks.getItemTitle(mobile[0]) != title) {
|
|
|
|
PlacesUtils.bookmarks.setItemTitle(mobile[0], title);
|
|
|
|
}
|
2009-12-11 00:12:14 +00:00
|
|
|
|
|
|
|
this.ignoreAll = false;
|
|
|
|
},
|
|
|
|
|
2011-04-07 22:55:29 +00:00
|
|
|
// This method is oddly structured, but the idea is to return as quickly as
|
|
|
|
// possible -- this handler gets called *every time* a bookmark changes, for
|
2012-02-24 12:42:32 +00:00
|
|
|
// *each change*.
|
2011-05-17 20:53:23 +00:00
|
|
|
onItemChanged: function BMT_onItemChanged(itemId, property, isAnno, value,
|
|
|
|
lastModified, itemType, parentId,
|
|
|
|
guid, parentGuid) {
|
2011-04-07 22:55:29 +00:00
|
|
|
// Quicker checks first.
|
2011-04-07 23:32:20 +00:00
|
|
|
if (this.ignoreAll)
|
2009-12-11 00:12:14 +00:00
|
|
|
return;
|
2009-08-25 23:15:05 +00:00
|
|
|
|
2011-04-07 23:32:20 +00:00
|
|
|
if (isAnno && (ANNOS_TO_TRACK.indexOf(property) == -1))
|
2011-04-07 22:55:29 +00:00
|
|
|
// Ignore annotations except for the ones that we sync.
|
2009-06-16 23:16:39 +00:00
|
|
|
return;
|
2009-02-02 19:43:06 +00:00
|
|
|
|
2011-04-07 23:32:20 +00:00
|
|
|
// Ignore favicon changes to avoid unnecessary churn.
|
|
|
|
if (property == "favicon")
|
|
|
|
return;
|
|
|
|
|
2011-05-17 20:53:23 +00:00
|
|
|
if (this._ignore(itemId, parentId, guid))
|
2010-01-19 19:24:00 +00:00
|
|
|
return;
|
|
|
|
|
2009-01-13 23:55:35 +00:00
|
|
|
this._log.trace("onItemChanged: " + itemId +
|
2009-01-14 00:55:51 +00:00
|
|
|
(", " + property + (isAnno? " (anno)" : "")) +
|
2011-02-07 19:25:47 +00:00
|
|
|
(value ? (" = \"" + value + "\"") : ""));
|
2011-05-18 21:27:39 +00:00
|
|
|
this._add(itemId, guid);
|
2008-06-03 19:38:48 +00:00
|
|
|
},
|
|
|
|
|
2011-05-17 20:53:23 +00:00
|
|
|
onItemMoved: function BMT_onItemMoved(itemId, oldParent, oldIndex,
|
|
|
|
newParent, newIndex, itemType,
|
|
|
|
guid, oldParentGuid, newParentGuid) {
|
|
|
|
if (this._ignore(itemId, newParent, guid))
|
2009-02-02 19:43:06 +00:00
|
|
|
return;
|
|
|
|
|
2008-12-06 08:12:40 +00:00
|
|
|
this._log.trace("onItemMoved: " + itemId);
|
2011-05-18 21:27:39 +00:00
|
|
|
this._add(oldParent, oldParentGuid);
|
2010-12-06 23:51:56 +00:00
|
|
|
if (oldParent != newParent) {
|
2011-05-18 21:27:39 +00:00
|
|
|
this._add(itemId, guid);
|
|
|
|
this._add(newParent, newParentGuid);
|
2010-12-06 23:51:56 +00:00
|
|
|
}
|
2010-02-03 23:34:42 +00:00
|
|
|
|
|
|
|
// Remove any position annotations now that the user moved the item
|
2011-05-20 01:08:22 +00:00
|
|
|
PlacesUtils.annotations.removeItemAnnotation(itemId, PARENT_ANNO);
|
2008-11-20 00:21:12 +00:00
|
|
|
},
|
2008-06-03 19:38:48 +00:00
|
|
|
|
2011-05-17 20:53:23 +00:00
|
|
|
onBeginUpdateBatch: function () {},
|
|
|
|
onEndUpdateBatch: function () {},
|
2013-02-06 19:48:56 +00:00
|
|
|
onItemVisited: function () {}
|
2008-11-07 03:18:46 +00:00
|
|
|
};
|