Bug 1274708 Use Context.jsonStringify() in ExtensionStorage r?kmag
MozReview-Commit-ID: Ba1w33Jl42n
--- a/toolkit/components/extensions/ExtensionStorage.jsm
+++ b/toolkit/components/extensions/ExtensionStorage.jsm
@@ -66,27 +66,23 @@ this.ExtensionStorage = {
extensionDir: Path.join(profileDir, "browser-extension-data"),
/**
* Sanitizes the given value, and returns a JSON-compatible
* representation of it, based on the privileges of the given global.
*
* @param {value} value
* The value to sanitize.
- * @param {object} global
- * The global for which to sanitize the value.
+ * @param {Context} context
+ * The extension context in which to sanitize the value
* @returns {value}
* The sanitized value.
*/
- sanitize(value, global) {
- // We can't trust that the global has privileges to access this
- // value enough to clone it using a privileged JSON object.
- let JSON_ = Cu.waiveXrays(global.JSON);
-
- let json = JSON_.stringify(value, jsonReplacer);
+ sanitize(value, context) {
+ let json = context.jsonStringify(value, jsonReplacer);
return JSON.parse(json);
},
getExtensionDir(extensionId) {
return Path.join(this.extensionDir, extensionId);
},
getStorageFile(extensionId) {
@@ -128,21 +124,21 @@ this.ExtensionStorage = {
"ExtensionStorage: Finish writing extension data",
promise);
return promise.then(() => {
AsyncShutdown.profileBeforeChange.removeBlocker(promise);
});
},
- set(extensionId, items, global) {
+ set(extensionId, items, context) {
return this.read(extensionId).then(extData => {
let changes = {};
for (let prop in items) {
- let item = this.sanitize(items[prop], global);
+ let item = this.sanitize(items[prop], context);
changes[prop] = {oldValue: extData[prop], newValue: item};
extData[prop] = item;
}
this.notifyListeners(extensionId, changes);
return this.write(extensionId);
});
--- a/toolkit/components/extensions/ext-storage.js
+++ b/toolkit/components/extensions/ext-storage.js
@@ -13,17 +13,17 @@ var {
extensions.registerSchemaAPI("storage", (extension, context) => {
return {
storage: {
local: {
get: function(keys) {
return ExtensionStorage.get(extension.id, keys);
},
set: function(items) {
- return ExtensionStorage.set(extension.id, items, context.cloneScope);
+ return ExtensionStorage.set(extension.id, items, context);
},
remove: function(items) {
return ExtensionStorage.remove(extension.id, items);
},
clear: function() {
return ExtensionStorage.clear(extension.id);
},
},