diff --git a/toolkit/components/social/FrameWorker.jsm b/toolkit/components/social/FrameWorker.jsm index eeffc3dcc9b..e2fabf559b7 100644 --- a/toolkit/components/social/FrameWorker.jsm +++ b/toolkit/components/social/FrameWorker.jsm @@ -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); } };