зеркало из https://github.com/mozilla/gecko-dev.git
Bug 524091 - Remove microsummaries support. (Sync changes)
r=philikon
This commit is contained in:
Родитель
2ded168118
Коммит
2674c0a38d
|
@ -40,7 +40,7 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const EXPORTED_SYMBOLS = ['BookmarksEngine', "PlacesItem", "Bookmark",
|
||||
"BookmarkFolder", "BookmarkMicsum", "BookmarkQuery",
|
||||
"BookmarkFolder", "BookmarkQuery",
|
||||
"Livemark", "BookmarkSeparator"];
|
||||
|
||||
const Cc = Components.classes;
|
||||
|
@ -50,17 +50,15 @@ const Cu = Components.utils;
|
|||
const ALLBOOKMARKS_ANNO = "AllBookmarks";
|
||||
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
||||
const SIDEBAR_ANNO = "bookmarkProperties/loadInSidebar";
|
||||
const STATICTITLE_ANNO = "bookmarks/staticTitle";
|
||||
const FEEDURI_ANNO = "livemark/feedURI";
|
||||
const SITEURI_ANNO = "livemark/siteURI";
|
||||
const GENERATORURI_ANNO = "microsummary/generatorURI";
|
||||
const MOBILEROOT_ANNO = "mobile/bookmarksRoot";
|
||||
const MOBILE_ANNO = "MobileBookmarks";
|
||||
const EXCLUDEBACKUP_ANNO = "places/excludeFromBackup";
|
||||
const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark";
|
||||
const PARENT_ANNO = "sync/parent";
|
||||
const ANNOS_TO_TRACK = [DESCRIPTION_ANNO, SIDEBAR_ANNO, STATICTITLE_ANNO,
|
||||
FEEDURI_ANNO, SITEURI_ANNO, GENERATORURI_ANNO];
|
||||
const ANNOS_TO_TRACK = [DESCRIPTION_ANNO, SIDEBAR_ANNO,
|
||||
FEEDURI_ANNO, SITEURI_ANNO];
|
||||
|
||||
const SERVICE_NOT_SUPPORTED = "Service not supported on this platform";
|
||||
const FOLDER_SORTINDEX = 1000000;
|
||||
|
@ -92,9 +90,8 @@ PlacesItem.prototype = {
|
|||
getTypeObject: function PlacesItem_getTypeObject(type) {
|
||||
switch (type) {
|
||||
case "bookmark":
|
||||
return Bookmark;
|
||||
case "microsummary":
|
||||
return BookmarkMicsum;
|
||||
return Bookmark;
|
||||
case "query":
|
||||
return BookmarkQuery;
|
||||
case "folder":
|
||||
|
@ -127,16 +124,6 @@ Bookmark.prototype = {
|
|||
Utils.deferGetSet(Bookmark, "cleartext", ["title", "bmkUri", "description",
|
||||
"loadInSidebar", "tags", "keyword"]);
|
||||
|
||||
function BookmarkMicsum(collection, id) {
|
||||
Bookmark.call(this, collection, id, "microsummary");
|
||||
}
|
||||
BookmarkMicsum.prototype = {
|
||||
__proto__: Bookmark.prototype,
|
||||
_logName: "Record.BookmarkMicsum",
|
||||
};
|
||||
|
||||
Utils.deferGetSet(BookmarkMicsum, "cleartext", ["generatorUri", "staticTitle"]);
|
||||
|
||||
function BookmarkQuery(collection, id) {
|
||||
Bookmark.call(this, collection, id, "query");
|
||||
}
|
||||
|
@ -431,7 +418,6 @@ function BookmarksStore(name) {
|
|||
this.__bms = null;
|
||||
this.__hsvc = null;
|
||||
this.__ls = null;
|
||||
this.__ms = null;
|
||||
this.__ts = null;
|
||||
for each ([query, stmt] in Iterator(this._stmts))
|
||||
stmt.finalize();
|
||||
|
@ -465,22 +451,6 @@ BookmarksStore.prototype = {
|
|||
return this.__ls;
|
||||
},
|
||||
|
||||
__ms: null,
|
||||
get _ms() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
return this.__ms;
|
||||
},
|
||||
|
||||
__ts: null,
|
||||
get _ts() {
|
||||
if (!this.__ts)
|
||||
|
@ -661,8 +631,6 @@ BookmarksStore.prototype = {
|
|||
return "folder";
|
||||
|
||||
case bms.TYPE_BOOKMARK:
|
||||
if (this._ms && this._ms.hasMicrosummary(itemId))
|
||||
return "microsummary";
|
||||
let bmkUri = bms.getBookmarkURI(itemId).spec;
|
||||
if (bmkUri.search(/^place:/) == 0)
|
||||
return "query";
|
||||
|
@ -720,22 +688,6 @@ BookmarksStore.prototype = {
|
|||
Svc.Annos.EXPIRE_NEVER);
|
||||
}
|
||||
|
||||
if (record.type == "microsummary") {
|
||||
this._log.debug(" \-> is a microsummary");
|
||||
Svc.Annos.setItemAnnotation(newId, STATICTITLE_ANNO,
|
||||
record.staticTitle || "", 0,
|
||||
Svc.Annos.EXPIRE_NEVER);
|
||||
let genURI = Utils.makeURI(record.generatorUri);
|
||||
if (this._ms) {
|
||||
try {
|
||||
let micsum = this._ms.createMicrosummary(uri, genURI);
|
||||
this._ms.setMicrosummary(newId, micsum);
|
||||
}
|
||||
catch(ex) { /* ignore "missing local generator" exceptions */ }
|
||||
}
|
||||
else
|
||||
this._log.warn("Can't create microsummary -- not supported.");
|
||||
}
|
||||
} break;
|
||||
case "folder":
|
||||
newId = this._bms.createFolder(record._parent, record.title,
|
||||
|
@ -890,20 +842,6 @@ BookmarksStore.prototype = {
|
|||
Svc.Annos.removeItemAnnotation(itemId, SIDEBAR_ANNO);
|
||||
}
|
||||
break;
|
||||
case "generatorUri": {
|
||||
try {
|
||||
let micsumURI = this._bms.getBookmarkURI(itemId);
|
||||
let genURI = Utils.makeURI(val);
|
||||
if (this._ms == SERVICE_NOT_SUPPORTED)
|
||||
this._log.warn("Can't create microsummary -- not supported.");
|
||||
else {
|
||||
let micsum = this._ms.createMicrosummary(micsumURI, genURI);
|
||||
this._ms.setMicrosummary(itemId, micsum);
|
||||
}
|
||||
} catch (e) {
|
||||
this._log.debug("Could not set microsummary generator URI: " + e);
|
||||
}
|
||||
} break;
|
||||
case "queryId":
|
||||
Svc.Annos.setItemAnnotation(itemId, SMART_BOOKMARKS_ANNO, val, 0,
|
||||
Svc.Annos.EXPIRE_NEVER);
|
||||
|
@ -984,14 +922,6 @@ BookmarksStore.prototype = {
|
|||
return Svc.Annos.itemHasAnnotation(id, SIDEBAR_ANNO);
|
||||
},
|
||||
|
||||
_getStaticTitle: function BStore__getStaticTitle(id) {
|
||||
try {
|
||||
return Svc.Annos.getItemAnnotation(id, STATICTITLE_ANNO);
|
||||
} catch (e) {
|
||||
return "";
|
||||
}
|
||||
},
|
||||
|
||||
get _childGUIDsStm() {
|
||||
return this._getStmt(
|
||||
"SELECT id AS item_id, guid " +
|
||||
|
@ -1028,13 +958,6 @@ BookmarksStore.prototype = {
|
|||
switch (this._bms.getItemType(placeId)) {
|
||||
case this._bms.TYPE_BOOKMARK:
|
||||
let bmkUri = this._bms.getBookmarkURI(placeId).spec;
|
||||
if (this._ms && this._ms.hasMicrosummary(placeId)) {
|
||||
record = new BookmarkMicsum(collection, id);
|
||||
let micsum = this._ms.getMicrosummary(placeId);
|
||||
record.generatorUri = micsum.generator.uri.spec; // breaks local generators
|
||||
record.staticTitle = this._getStaticTitle(placeId);
|
||||
}
|
||||
else {
|
||||
if (bmkUri.search(/^place:/) == 0) {
|
||||
record = new BookmarkQuery(collection, id);
|
||||
|
||||
|
@ -1061,10 +984,10 @@ BookmarksStore.prototype = {
|
|||
}
|
||||
catch(ex) {}
|
||||
}
|
||||
else
|
||||
else {
|
||||
record = new Bookmark(collection, id);
|
||||
record.title = this._bms.getItemTitle(placeId);
|
||||
}
|
||||
record.title = this._bms.getItemTitle(placeId);
|
||||
|
||||
record.parentName = Svc.Bookmark.getItemTitle(parent);
|
||||
record.bmkUri = bmkUri;
|
||||
|
|
|
@ -402,3 +402,20 @@ function encryptPayload(cleartext) {
|
|||
hmac: Utils.sha256HMAC(cleartext, Utils.makeHMACKey(""))};
|
||||
}
|
||||
|
||||
function do_check_throws(aFunc, aResult, aStack)
|
||||
{
|
||||
if (!aStack) {
|
||||
try {
|
||||
// We might not have a 'Components' object.
|
||||
aStack = Components.stack.caller;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
try {
|
||||
aFunc();
|
||||
} catch (e) {
|
||||
do_check_eq(e.result, aResult, aStack);
|
||||
return;
|
||||
}
|
||||
do_throw("Expected result " + aResult + ", none thrown.", aStack);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// Tests that Sync can correctly handle a legacy microsummary record
|
||||
|
||||
Cu.import("resource://services-sync/engines.js");
|
||||
Cu.import("resource://services-sync/engines/bookmarks.js");
|
||||
Cu.import("resource://services-sync/record.js");
|
||||
Cu.import("resource://services-sync/log4moz.js");
|
||||
Cu.import("resource://services-sync/util.js");
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/PlacesUtils.jsm");
|
||||
|
||||
const GENERATORURI_ANNO = "microsummary/generatorURI";
|
||||
const STATICTITLE_ANNO = "bookmarks/staticTitle";
|
||||
|
||||
const TEST_URL = "http://micsum.mozilla.org/";
|
||||
const TEST_TITLE = "A microsummarized bookmark"
|
||||
const GENERATOR_URL = "http://generate.micsum/"
|
||||
const STATIC_TITLE = "Static title"
|
||||
|
||||
function newMicrosummary(url, title) {
|
||||
let id = PlacesUtils.bookmarks.insertBookmark(
|
||||
PlacesUtils.unfiledBookmarksFolderId, NetUtil.newURI(url),
|
||||
PlacesUtils.bookmarks.DEFAULT_INDEX, title
|
||||
);
|
||||
PlacesUtils.annotations.setItemAnnotation(id, GENERATORURI_ANNO,
|
||||
GENERATOR_URL, 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
PlacesUtils.annotations.setItemAnnotation(id, STATICTITLE_ANNO,
|
||||
"Static title", 0,
|
||||
PlacesUtils.annotations.EXPIRE_NEVER);
|
||||
return id;
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
||||
Engines.register(BookmarksEngine);
|
||||
let engine = Engines.get("bookmarks");
|
||||
let store = engine._store;
|
||||
|
||||
// Clean up.
|
||||
store.wipe();
|
||||
|
||||
initTestLogging("Trace");
|
||||
Log4Moz.repository.getLogger("Engine.Bookmarks").level = Log4Moz.Level.Trace;
|
||||
|
||||
_("Create a microsummarized bookmark.");
|
||||
let id = newMicrosummary(TEST_URL, TEST_TITLE);
|
||||
let guid = store.GUIDForId(id);
|
||||
_("GUID: " + guid);
|
||||
do_check_true(!!guid);
|
||||
|
||||
_("Create record object and verify that it's sane.");
|
||||
let record = store.createRecord(guid);
|
||||
do_check_true(record instanceof Bookmark);
|
||||
do_check_eq(record.bmkUri, TEST_URL);
|
||||
|
||||
_("Make sure the new record does not carry the microsummaries annotations.");
|
||||
do_check_false("staticTitle" in record);
|
||||
do_check_false("generatorUri" in record);
|
||||
|
||||
_("Remove the bookmark from Places.");
|
||||
PlacesUtils.bookmarks.removeItem(id);
|
||||
|
||||
_("Convert record to the old microsummaries one.");
|
||||
record.staticTitle = STATIC_TITLE;
|
||||
record.generatorUri = GENERATOR_URL;
|
||||
record.type = "microsummary";
|
||||
|
||||
_("Apply the modified record as incoming data.");
|
||||
store.applyIncoming(record);
|
||||
|
||||
_("Verify it has been created correctly as a simple Bookmark.");
|
||||
id = store.idForGUID(record.id);
|
||||
do_check_eq(store.GUIDForId(id), record.id);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemType(id),
|
||||
PlacesUtils.bookmarks.TYPE_BOOKMARK);
|
||||
do_check_eq(PlacesUtils.bookmarks.getBookmarkURI(id).spec, TEST_URL);
|
||||
do_check_eq(PlacesUtils.bookmarks.getItemTitle(id), TEST_TITLE);
|
||||
do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(id),
|
||||
PlacesUtils.unfiledBookmarksFolderId);
|
||||
do_check_eq(PlacesUtils.bookmarks.getKeywordForBookmark(id), null);
|
||||
|
||||
do_check_throws(
|
||||
function () PlacesUtils.annotations.getItemAnnotation(id, GENERATORURI_ANNO),
|
||||
Cr.NS_ERROR_NOT_AVAILABLE
|
||||
);
|
||||
|
||||
do_check_throws(
|
||||
function () PlacesUtils.annotations.getItemAnnotation(id, STATICTITLE_ANNO),
|
||||
Cr.NS_ERROR_NOT_AVAILABLE
|
||||
);
|
||||
|
||||
// Clean up.
|
||||
store.wipe();
|
||||
}
|
|
@ -247,7 +247,7 @@ function test_tracking() {
|
|||
|
||||
function test_onItemChanged() {
|
||||
// Anno that's in ANNOS_TO_TRACK.
|
||||
const GENERATOR_ANNO = "microsummary/generatorURI";
|
||||
const DESCRIPTION_ANNO = "bookmarkProperties/description";
|
||||
|
||||
_("Verify we've got an empty tracker to work with.");
|
||||
let tracker = engine._tracker;
|
||||
|
@ -268,7 +268,7 @@ function test_onItemChanged() {
|
|||
_("GUID: " + bGUID);
|
||||
|
||||
Svc.Obs.notify("weave:engine:start-tracking");
|
||||
Svc.Annos.setItemAnnotation(b, GENERATOR_ANNO, "http://foo.bar/", 0,
|
||||
Svc.Annos.setItemAnnotation(b, DESCRIPTION_ANNO, "A test description", 0,
|
||||
Svc.Annos.EXPIRE_NEVER);
|
||||
do_check_true(tracker.changedIDs[bGUID] > 0);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче