Permalink
Browse files

Closes #21 nuke sandboxes for destroyed inner windows on FF 17+

  • Loading branch information...
1 parent a8e4f4b commit 98cecd57fdfc05679fb1082477e9c3f2ed7a4159 @erikvold erikvold committed Sep 22, 2012
@@ -31,7 +31,7 @@ const tests = {
var file = uri.file;
return file.parent.equals(this._tmpDir) && file.leafName != "newscript.user.js";
}
-}
+};
const Scriptish_manager = {
setup: function(options) {
@@ -6,7 +6,7 @@ var EXPORTED_SYMBOLS = [
const Cu = Components.utils;
Cu.import("resource://scriptish/constants.js");
-lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log"]);
+lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log", "Scriptish_logError"]);
lazyImport(this, "resource://scriptish/prefmanager.js", ["Scriptish_prefRoot"]);
lazyImport(this, "resource://scriptish/api.js", ["GM_API"]);
lazyImport(this, "resource://scriptish/api/GM_sandboxScripts.js", ["GM_sandboxScripts"]);
@@ -25,23 +25,21 @@ const {nsIDOMXPathResult: XPATH_RESULT} = Ci;
function Scriptish_injectScripts(options) {
var {scripts, url, safeWin} = options;
-
- try {
- if ("Fennec" != Services.appinfo.name) {
- var chromeWin = Scriptish_getBrowserForContentWindow(safeWin).wrappedJSObject;
- if (!chromeWin || !chromeWin.Scriptish_BrowserUI) return;
- }
- }
- catch (e) {}
+ var chromeWin = Scriptish_getBrowserForContentWindow(safeWin).wrappedJSObject;
+ if (!chromeWin || !chromeWin.Scriptish_BrowserUI) return;
if (0 >= scripts.length) return;
let unsafeContentWin = safeWin.wrappedJSObject;
- let delays = [];
let winID = Scriptish_getWindowIDs(safeWin).innerID;
+ let delays = [];
+
+ // window destroyed handler
Scriptish_windowUnloader(function() {
+ // destroy a possible inject @delay
for (let [, id] in Iterator(delays)) gTimer.clearTimeout(id);
+ delays.length = 0;
}, winID);
for (var i = 0, e = scripts.length; i < e; ++i) {
@@ -100,8 +98,17 @@ function Scriptish_injectScripts(options) {
delays.push(gTimer.setTimeout(function() {
Scriptish_evalInSandbox(script, sandbox, safeWin, options);
}, delay));
- } else {
+ }
+ else {
Scriptish_evalInSandbox(script, sandbox, safeWin, options);
}
+
+ // window destroyed handler
+ if ("nukeSandbox" in Cu) {
+ Scriptish_windowUnloader(function() {
+ // try to nuke the sandbox (FF 17+ see bug 769273)
+ Cu.nukeSandbox(sandbox);
+ }, winID);
+ }
}
}
@@ -1,26 +1,25 @@
var EXPORTED_SYMBOLS = ["Scriptish_windowUnloader"];
Components.utils.import("resource://scriptish/constants.js");
-lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log"]);
+lazyImport(this, "resource://scriptish/logging.js", ["Scriptish_log", "Scriptish_logError"]);
const winUnloaders = {};
-function Unloader(aFunc, aInnerID) {
- this.unload = aFunc;
- this.innerID = aInnerID;
-}
-
const observer = {
observe: function(aSubject, aTopic, aData) {
var innerID = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
var unloaders = winUnloaders[innerID];
-
if (!unloaders) return;
- for (var i = 0, e = unloaders.length - 1; ~i; i--) {
- unloaders[i].unload();
+ for (var i = unloaders.length - 1; ~i; i--) {
+ try {
+ unloaders[i]();
+ }
+ catch(e) {
+ Scriptish_logError(e);
+ }
}
- delete winUnloaders[innerID];
+ winUnloaders[innerID] = null;
}
};
Services.obs.addObserver(observer, "inner-window-destroyed", false);
@@ -29,5 +28,5 @@ const Scriptish_windowUnloader = function(aUnloader, aInnerID) {
if (!winUnloaders[aInnerID])
winUnloaders[aInnerID] = [];
- winUnloaders[aInnerID].push(new Unloader(aUnloader, aInnerID));
+ winUnloaders[aInnerID].push(aUnloader);
};

0 comments on commit 98cecd5

Please sign in to comment.