mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-11-03 19:05:35 +00:00
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
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,
|
|
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);
|
|
}
|
|
});
|
|
},
|
|
clear: function(callback) {
|
|
ExtensionStorage.clear(extension.id).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(),
|
|
},
|
|
};
|
|
});
|