mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-12 15:02:11 +00:00
08997000eb
Backed out changeset 647025383676 (bug 1202902) Backed out changeset d70c7fe532c6 (bug 1202902)
51 lines
1.4 KiB
JavaScript
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(),
|
|
},
|
|
};
|
|
});
|