Bug 790201. Nuke social worker sandbox on shutdown. r=mhammond

This commit is contained in:
Felipe Gomes 2012-10-05 17:22:09 -07:00
parent 79030af494
commit ad36389b3d

View File

@ -77,7 +77,7 @@ function FrameWorker(url, name) {
if (!doc.defaultView || doc.defaultView != self.frame.contentWindow) {
return;
}
Services.obs.removeObserver(injectController, "document-element-inserted", false);
Services.obs.removeObserver(injectController, "document-element-inserted");
try {
self.createSandbox();
} catch (e) {
@ -103,8 +103,11 @@ FrameWorker.prototype = {
'location'];
workerAPI.forEach(function(fn) {
try {
// XXX Need to unwrap for this to work - find out why!
sandbox[fn] = XPCNativeWrapper.unwrap(workerWindow)[fn];
sandbox[fn] = workerWindow[fn];
// Bug 798660 - XHR has issues in a sandbox and need
// to be unwrapped to work
if (fn == "XMLHttpRequest")
sandbox[fn] = XPCNativeWrapper.unwrap(workerWindow)[fn];
}
catch(e) {
Cu.reportError("FrameWorker: failed to import API "+fn+"\n"+e+"\n");
@ -153,8 +156,14 @@ FrameWorker.prototype = {
workerWindow.addEventListener(t, l, c)
};
// This is necessary to keep the sandbox alive
this.sandbox = sandbox;
Services.obs.addObserver(function cleanupSandbox () {
Services.obs.removeObserver(cleanupSandbox, "xpcom-shutdown");
Cu.nukeSandbox(sandbox);
}, "xpcom-shutdown", false);
let worker = this;
workerWindow.addEventListener("load", function loadListener() {
@ -226,6 +235,8 @@ FrameWorker.prototype = {
// now nuke the iframe itself and forget everything about this worker.
this.frame.parentNode.removeChild(this.frame);
}.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
Cu.nukeSandbox(this.sandbox);
}
};