Bug 1038844 - Use the opt-out for the SpecialPowers scope. r=mrbkap,r=ted

This commit is contained in:
Bobby Holley 2014-07-17 21:34:48 -07:00
parent 7239458847
commit 329c1ce903
2 changed files with 7 additions and 45 deletions

View File

@ -106,15 +106,6 @@ SpecialPowers.prototype.executeAfterFlushingMessageQueue = function(aCallback) {
sendAsyncMessage("SPPingService", { op: "ping" });
};
// Expose everything but internal APIs (starting with underscores) to
// web content. We cannot use Object.keys to view SpecialPowers.prototype since
// we are using the functions from SpecialPowersAPI.prototype
SpecialPowers.prototype.__exposedProps__ = {};
for (var i in SpecialPowers.prototype) {
if (i.charAt(0) != "_")
SpecialPowers.prototype.__exposedProps__[i] = "r";
}
// Attach our API to the window.
function attachSpecialPowersToWindow(aWindow) {
try {

View File

@ -18,6 +18,10 @@ Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
// Allow stuff from this scope to be accessed from non-privileged scopes. This
// would crash if used outside of automation.
Cu.forcePermissiveCOWs();
function SpecialPowersAPI() {
this._consoleListeners = [];
this._encounteredCrashDumpFiles = [];
@ -223,27 +227,6 @@ function crawlProtoChain(obj, fn) {
return undefined;
};
/*
* We want to waive the __exposedProps__ security check for SpecialPowers-wrapped
* objects. We do this by creating a proxy singleton that just always returns 'rw'
* for any property name.
*/
function ExposedPropsWaiverHandler() {
// NB: XPConnect denies access if the relevant member of __exposedProps__ is not
// enumerable.
var _permit = { value: 'rw', writable: false, configurable: false, enumerable: true };
return {
getOwnPropertyDescriptor: function(name) { return _permit; },
getPropertyDescriptor: function(name) { return _permit; },
getOwnPropertyNames: function() { throw Error("Can't enumerate ExposedPropsWaiver"); },
getPropertyNames: function() { throw Error("Can't enumerate ExposedPropsWaiver"); },
enumerate: function() { throw Error("Can't enumerate ExposedPropsWaiver"); },
defineProperty: function(name) { throw Error("Can't define props on ExposedPropsWaiver"); },
delete: function(name) { throw Error("Can't delete props from ExposedPropsWaiver"); }
};
};
var ExposedPropsWaiver = Proxy.create(ExposedPropsWaiverHandler());
function SpecialPowersHandler(obj) {
this.wrappedObject = obj;
};
@ -256,10 +239,6 @@ SpecialPowersHandler.prototype.doGetPropertyDescriptor = function(name, own) {
if (name == "SpecialPowers_wrappedObject")
return { value: this.wrappedObject, writeable: false, configurable: false, enumerable: false };
// Handle __exposedProps__.
if (name == "__exposedProps__")
return { value: ExposedPropsWaiver, writable: false, configurable: false, enumerable: false };
//
// Call through to the wrapped object.
//
@ -445,11 +424,6 @@ SPConsoleListener.prototype = {
m.isStrict = ((msg.flags & Ci.nsIScriptError.strictFlag) === 1);
}
// expose all props of 'm' as read-only
let expose = {};
for (let prop in m)
expose[prop] = 'r';
m.__exposedProps__ = expose;
Object.freeze(m);
this.callback.call(undefined, m);
@ -470,7 +444,7 @@ function wrapCallback(cb) {
function wrapCallbackObject(obj) {
obj = Cu.waiveXrays(obj);
var wrapper = { __exposedProps__: ExposedPropsWaiver };
var wrapper = {};
for (var i in obj) {
if (typeof obj[i] == 'function')
wrapper[i] = wrapCallback(obj[i]);
@ -528,9 +502,7 @@ SpecialPowersAPI.prototype = {
* Create blank privileged objects to use as out-params for privileged functions.
*/
createBlankObject: function () {
var obj = new Object;
obj.__exposedProps__ = ExposedPropsWaiver;
return obj;
return new Object;
},
/*
@ -1477,13 +1449,12 @@ SpecialPowersAPI.prototype = {
getDOMRequestService: function() {
var serv = Services.DOMRequest;
var res = { __exposedProps__: {} };
var res = {};
var props = ["createRequest", "createCursor", "fireError", "fireSuccess",
"fireDone", "fireDetailedError"];
for (var i in props) {
let prop = props[i];
res[prop] = function() { return serv[prop].apply(serv, arguments) };
res.__exposedProps__[prop] = "r";
}
return res;
},