Carsten "Tomcat" Book 08997000eb Backed out 2 changesets (bug 1202902) to recking bug 1202902 to be able to reopen inbound on a CLOSED TREE
Backed out changeset 647025383676 (bug 1202902)
Backed out changeset d70c7fe532c6 (bug 1202902)
2015-10-07 14:03:21 +02:00

51 lines
1.4 KiB
JavaScript

var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
XPCOMUtils.defineLazyModuleGetter(this, "ExtensionStorage",
"resource://gre/modules/ExtensionStorage.jsm");
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
var {
EventManager,
ignoreEvent,
runSafe,
} = ExtensionUtils;
extensions.registerPrivilegedAPI("storage", (extension, context) => {
return {
storage: {
local: {
get: function(keys, callback) {
ExtensionStorage.get(extension.id, keys).then(result => {
runSafe(context, callback, result);
});
},
set: function(items, callback) {
ExtensionStorage.set(extension.id, items).then(() => {
if (callback) {
runSafe(context, callback);
}
});
},
remove: function(items, callback) {
ExtensionStorage.remove(extension.id, items).then(() => {
if (callback) {
runSafe(context, callback);
}
});
},
},
onChanged: new EventManager(context, "storage.local.onChanged", fire => {
let listener = changes => {
fire(changes, "local");
};
ExtensionStorage.addOnChangedListener(extension.id, listener);
return () => {
ExtensionStorage.removeOnChangedListener(extension.id, listener);
};
}).api(),
},
};
});