Commit 9158488b authored by Tatiana Meshkova's avatar Tatiana Meshkova

Added basic implementation for Bookmarks/History fetcher from mozilla Sync account

parent f37701aa
......@@ -10,15 +10,19 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
function EmbedLiteSyncServiceImpotUtils()
{
Cu.import("resource://services-common/log4moz.js");
Cu.import("resource://services-sync/main.js");
Cu.import("resource://services-sync/constants.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/policies.js");
Cu.import("resource://services-sync/util.js");
Cu.import("resource://services-sync/engines.js");
Cu.import("resource://services-sync/engines/tabs.js")
Cu.import("resource://services-sync/record.js");
Cu.import("resource://services-sync/engines/history.js");
Cu.import("chrome://embedlite/content/sync/bookmarks.js");
}
// Common helper service
......@@ -27,6 +31,7 @@ function EmbedLiteSyncService()
{
}
EmbedLiteSyncService.prototype = {
classID: Components.ID("{36896ad0-9b49-11e2-ae7c-6f7993904c41}"),
......@@ -35,6 +40,7 @@ EmbedLiteSyncService.prototype = {
// Engine DownloadManager notifications
case "app-startup": {
dump("EmbedLiteSyncService app-startup\n");
Services.prefs.setCharPref("services.sync.registerEngines", "Bookmarks,History");
Services.obs.addObserver(this, "embedui:initsync", true);
break;
}
......@@ -43,17 +49,43 @@ EmbedLiteSyncService.prototype = {
var data = JSON.parse(aData);
EmbedLiteSyncServiceImpotUtils();
Service.login(data.username, data.password, data.key);
Utils.jsonSave("foo", {}, ["v1", "v2"], function(error) {
Utils.jsonLoad("foo", {}, function(val) {
let foo = val;
dump("Load foo:" + foo + "\n");
});
});
//this.embedLiteSyncServiceFetchBookmarks();
//this.embedLiteSyncServiceFetchHistory();
break;
}
}
},
embedLiteSyncServiceFetchBookmarks: function () {
let collection = "bookmarks";
let key = Service.collectionKeys.keyForCollection(this.name);
let coll = new Collection(Service.storageURL + collection, PlacesItem, Service);
coll.full = true;
coll.recordHandler = function(item) {
item.collection = collection;
item.decrypt(key);
if (item.cleartext.type == "bookmark") {
let decobj = item.cleartext;
dump("Title: " + decobj.title + ", Uri: " + decobj.bmkUri + "\n");
}
};
coll.get();
},
embedLiteSyncServiceFetchHistory: function () {
let collection = "history";
let key = Service.collectionKeys.keyForCollection(this.name);
let coll = new Collection(Service.storageURL + collection, HistoryRec, Service);
coll.full = true;
coll.recordHandler = function(item) {
item.collection = collection;
item.decrypt(key);
dump("Title: " + item.cleartext.title + ", Uri:" + item.cleartext.histUri + "\n");
};
coll.get();
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference])
};
......
content embedlite embedlite/content/embedlite
......@@ -10,9 +10,14 @@ jsscripts_manifest_DATA = \
yahoo.xml \
$(NULL)
sync_engine_manifestdir=$(libdir)/mozembedlite/chrome/embedlite/content/sync
sync_engine_manifest_DATA = \
sync/bookmarks.js \
$(NULL)
manifestsscript_manifestdir=$(libdir)/mozembedlite/chrome
manifestsscript_manifest_DATA = \
EmbedLiteJSScripts.manifest \
$(NULL)
INCLUDES = $(DEPS_CFLAGS)
INCLUDES = $(DEPS_CFLAGS)
/* 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/. */
this.EXPORTED_SYMBOLS = ["PlacesItem", "Bookmark",
"BookmarkFolder", "BookmarkQuery",
"Livemark", "BookmarkSeparator"];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://services-sync/record.js");
Cu.import("resource://services-sync/util.js");
this.PlacesItem = function PlacesItem(collection, id, type) {
CryptoWrapper.call(this, collection, id);
this.type = type || "item";
}
PlacesItem.prototype = {
decrypt: function PlacesItem_decrypt(keyBundle) {
// Do the normal CryptoWrapper decrypt, but change types before returning
let clear = CryptoWrapper.prototype.decrypt.call(this, keyBundle);
// 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":
return Bookmark;
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,
_logName: "Sync.Record.PlacesItem",
};
Utils.deferGetSet(PlacesItem,
"cleartext",
["hasDupe", "parentid", "parentName", "type"]);
this.Bookmark = function Bookmark(collection, id, type) {
PlacesItem.call(this, collection, id, type || "bookmark");
}
Bookmark.prototype = {
__proto__: PlacesItem.prototype,
_logName: "Sync.Record.Bookmark",
};
Utils.deferGetSet(Bookmark,
"cleartext",
["title", "bmkUri", "description",
"loadInSidebar", "tags", "keyword"]);
this.BookmarkQuery = function BookmarkQuery(collection, id) {
Bookmark.call(this, collection, id, "query");
}
BookmarkQuery.prototype = {
__proto__: Bookmark.prototype,
_logName: "Sync.Record.BookmarkQuery",
};
Utils.deferGetSet(BookmarkQuery,
"cleartext",
["folderName", "queryId"]);
this.BookmarkFolder = function BookmarkFolder(collection, id, type) {
PlacesItem.call(this, collection, id, type || "folder");
}
BookmarkFolder.prototype = {
__proto__: PlacesItem.prototype,
_logName: "Sync.Record.Folder",
};
Utils.deferGetSet(BookmarkFolder, "cleartext", ["description", "title",
"children"]);
this.Livemark = function Livemark(collection, id) {
BookmarkFolder.call(this, collection, id, "livemark");
}
Livemark.prototype = {
__proto__: BookmarkFolder.prototype,
_logName: "Sync.Record.Livemark",
};
Utils.deferGetSet(Livemark, "cleartext", ["siteUri", "feedUri"]);
this.BookmarkSeparator = function BookmarkSeparator(collection, id) {
PlacesItem.call(this, collection, id, "separator");
}
BookmarkSeparator.prototype = {
__proto__: PlacesItem.prototype,
_logName: "Sync.Record.Separator",
};
Utils.deferGetSet(BookmarkSeparator, "cleartext", "pos");
......@@ -54,7 +54,7 @@ rm -f $TARGET_DIR/chrome/EmbedLiteJSScripts.manifest;
ln -s $(pwd)/jsscripts/EmbedLiteJSScripts.manifest $TARGET_DIR/chrome/EmbedLiteJSScripts.manifest;
rm -rf $TARGET_DIR/chrome/embedlite;
mkdir -p $TARGET_DIR/chrome/embedlite/content;
mkdir -p $TARGET_DIR/chrome/embedlite/content/sync;
ln -s $(pwd)/jsscripts/embedhelper.js $TARGET_DIR/chrome/embedlite/content/embedhelper.js;
ln -s $(pwd)/jsscripts/SelectHelper.js $TARGET_DIR/chrome/embedlite/content/SelectHelper.js;
ln -s $(pwd)/jsscripts/SelectionHandler.js $TARGET_DIR/chrome/embedlite/content/SelectionHandler.js;
......@@ -64,6 +64,8 @@ ln -s $(pwd)/jsscripts/google.xml $TARGET_DIR/chrome/embedlite/content/google.xm
ln -s $(pwd)/jsscripts/bing.xml $TARGET_DIR/chrome/embedlite/content/bing.xml;
ln -s $(pwd)/jsscripts/yahoo.xml $TARGET_DIR/chrome/embedlite/content/yahoo.xml;
ln -s $(pwd)/jsscripts/sync/bookmarks.js $TARGET_DIR/chrome/embedlite/content/sync/bookmarks.js;
rm -f $TARGET_DIR/chrome/EmbedLiteOverrides.manifest;
ln -s $(pwd)/overrides/EmbedLiteOverrides.manifest $TARGET_DIR/chrome/EmbedLiteOverrides.manifest;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment