mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-09 12:51:09 +02:00
- Add `envType` to BaseContext. - Pass an explicit envType to all `registerSchemaAPI` invocations. - The factories passed to `registerSchemaAPI` will be split up later, so that content scripts (`content_child`) and addon pages can share common implementations. - The factories that implement the addon API will also be split up, to separate code running in the main process (`addon_parent`) from code running in a child process (`addon_child`). - Remove the use of a hardcoded list of `namespaces` from ProxyContext. Now `envType` is used to specify whether an API should be activated. MozReview-Commit-ID: Jiff8HIwG92 --HG-- extra : rebase_source : 946a3c0009a4e3223c2d10044b3099a94c845394
46 lines
1.3 KiB
JavaScript
46 lines
1.3 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,
|
|
} = ExtensionUtils;
|
|
|
|
function storageApiFactory(context) {
|
|
let {extension} = context;
|
|
return {
|
|
storage: {
|
|
local: {
|
|
get: function(keys) {
|
|
return ExtensionStorage.get(extension.id, keys);
|
|
},
|
|
set: function(items) {
|
|
return ExtensionStorage.set(extension.id, items, context);
|
|
},
|
|
remove: function(items) {
|
|
return ExtensionStorage.remove(extension.id, items);
|
|
},
|
|
clear: function() {
|
|
return ExtensionStorage.clear(extension.id);
|
|
},
|
|
},
|
|
|
|
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(),
|
|
},
|
|
};
|
|
}
|
|
extensions.registerSchemaAPI("storage", "addon_parent", storageApiFactory);
|
|
extensions.registerSchemaAPI("storage", "content_parent", storageApiFactory);
|