Cu.import("resource://gre/modules/CloudSync.jsm");
console.log(cloudSync); // Module is imported
Local device ID. Is unique.
let localId = cloudSync.local.id;
Local device name.
let localName = cloudSync.local.name;
Add an event handler for Tabs events. Valid type is change
. The callback receives no arguments.
function handleTabChange() {
// Tabs have changed.
}
cloudSync.tabs.addEventListener("change", handleTabChange);
Change events are emitted when a tab is opened or closed, when a tab is selected, or when the page changes for an open tab.
Remove an event handler. Pass the type and function that were passed to addEventListener.
cloudSync.tabs.removeEventListener("change", handleTabChange);
Merge remote tabs from upstream by updating existing items, adding new tabs, and deleting existing tabs. Accepts a client and a list of tabs. Returns a promise.
let remoteClient = {
id: "fawe78",
name: "My Firefox client",
};
var remoteTabs = [
{title: "Google",
url: "https://www.google.com",
icon: "https://www.google.com/favicon.ico",
lastUsed: 1400799296192390},
{title: "Reddit",
url: "http://www.reddit.com",
icon: "http://www.reddit.com/favicon.ico",
lastUsed: 1400799296192390
deleted: true},
];
cloudSync.tabs.mergeRemoteTabs(client, tabs).then(
function() {
console.log("merge complete");
}
);
Returns a promise. Passes a list of local tabs when complete.
cloudSync.tabs.getLocalTabs().then(
function(tabs) {
console.log(JSON.stringify(tabs));
}
);
Clears all tabs for a remote client.
let remoteClient = {
id: "fawe78",
name: "My Firefox client",
};
cloudSync.tabs.clearRemoteTabs(client);
Gets the named root folder, creating it if it doesn't exist. The root folder object has a number of methods (see the next section for details).
cloudSync.bookmarks.getRootFolder("My Bookmarks").then(
function(rootFolder) {
console.log(rootFolder);
}
);
This is a root folder object for bookmarks, created by cloudSync.bookmarks.getRootFolder
.
Bookmark type. Used in results objects.
var bookmarkType = rootFolder.BOOKMARK;
Folder type. Used in results objects.
var folderType = rootFolder.FOLDER;
Separator type. Used in results objects.
var separatorType = rootFolder.SEPARATOR;
Add an event handler for Tabs events. Valid types are add, remove, change, move
. The callback receives an ID corresponding to the target item.
function handleBoookmarkEvent(id) {
console.log("event for id:", id);
}
rootFolder.addEventListener("add", handleBookmarkEvent);
rootFolder.addEventListener("remove", handleBookmarkEvent);
rootFolder.addEventListener("change", handleBookmarkEvent);
rootFolder.addEventListener("move", handleBookmarkEvent);
Remove an event handler. Pass the type and function that were passed to addEventListener.
rootFolder.removeEventListener("add", handleBookmarkEvent);
rootFolder.removeEventListener("remove", handleBookmarkEvent);
rootFolder.removeEventListener("change", handleBookmarkEvent);
rootFolder.removeEventListener("move", handleBookmarkEvent);
Callback receives a list of items on the local client. Results have the following form:
{
id: "faw8e7f", // item guid
parent: "f7sydf87y", // parent folder guid
dateAdded: 1400799296192390, // timestamp
lastModified: 1400799296192390, // timestamp
uri: "https://www.google.ca", // null for FOLDER and SEPARATOR
title: "Google"
type: rootFolder.BOOKMARK, // should be one of rootFolder.{BOOKMARK, FOLDER, SEPARATOR},
index: 0 // must be unique among folder items
}
rootFolder.getLocalItems().then(
function(items) {
console.log(JSON.stringify(items));
}
);
Callback receives a list of items, specified by ID, on the local client. Results have the same form as getLocalItems()
above.
rootFolder.getLocalItemsById(["213r23f", "f22fy3f3"]).then(
function(items) {
console.log(JSON.stringify(items));
}
);
Merge remote items from upstream by updating existing items, adding new items, and deleting existing items. Folders are created first so that subsequent operations will succeed. Items have the same form as getLocalItems()
above. Items that do not have an ID will have an ID generated for them. The results structure will contain this generated ID.
rootFolder.mergeRemoteItems([
{
id: 'f2398f23',
type: rootFolder.FOLDER,
title: 'Folder 1',
parent: '9f8237f928'
},
{
id: '9f8237f928',
type: rootFolder.FOLDER,
title: 'Folder 0',
}
]).then(
function(items) {
console.log(items); // any generated IDs are filled in now
console.log("merge completed");
}
);