1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-28 11:12:26 +01:00

Move window-based code to separate Sandbox compartment and nuke the hell out of as much as possible on unload.

This commit is contained in:
Kris Maglione
2014-02-16 21:05:40 -08:00
parent 4f7214873c
commit fa3930b870
4 changed files with 37 additions and 21 deletions

View File

@@ -151,9 +151,13 @@ var Contexts = Module("contexts", {
for each (let hive in values(this.groupList.slice()))
util.trapErrors("destroy", hive, "shutdown");
for (let [name, plugin] in iter(this.modules.plugins.contexts))
for each (let plugin in this.modules.plugins.contexts) {
if (plugin && "onUnload" in plugin && callable(plugin.onUnload))
util.trapErrors("onUnload", plugin);
if (isinstance(plugin, ["Sandbox"]))
util.trapErrors("nukeSandbox", Cu, plugin);
}
},
signals: {

View File

@@ -89,12 +89,30 @@ var Modules = function Modules(window) {
Module.list = [];
Module.constructors = {};
const create = window.Object.create.bind(window.Object);
function newContext(proto, normal, name) {
if (normal)
return create(proto);
sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules,
sandboxName: name || ("Dactyl Sandbox " + ++_id),
wantXrays: false });
// Hack:
// sandbox.Object = jsmodules.Object;
sandbox.File = jsmodules.File;
sandbox.Math = jsmodules.Math;
sandbox.Set = jsmodules.Set;
return sandbox;
};
const BASES = [BASE, "resource://dactyl-local-content/"];
jsmodules = Cu.createObjectIn(window);
jsmodules = newContext(window, false, "Dactyl `jsmodules`");
jsmodules.NAME = "jsmodules";
const create = bind("create", jsmodules.Object);
const modules = update(create(jsmodules), {
yes_i_know_i_should_not_report_errors_in_these_branches_thanks: [],
@@ -130,21 +148,7 @@ var Modules = function Modules(window) {
}
},
newContext: function newContext(proto, normal, name) {
if (normal)
return create(proto);
sandbox = Components.utils.Sandbox(window, { sandboxPrototype: proto || modules,
sandboxName: name || ("Dactyl Sandbox " + ++_id),
wantXrays: false });
// Hack:
// sandbox.Object = jsmodules.Object;
sandbox.File = jsmodules.File;
sandbox.Math = jsmodules.Math;
sandbox.Set = jsmodules.Set;
return sandbox;
},
newContext: newContext,
get ownPropertyValues() array.compact(
Object.getOwnPropertyNames(this)
@@ -166,6 +170,7 @@ overlay.overlayWindow(Object.keys(config.overlays),
const modules = Modules(window);
modules.moduleManager = this;
this.modules = modules;
this.jsmodules = modules.jsmodules;
window.dactyl = { modules: modules };
@@ -225,6 +230,8 @@ overlay.overlayWindow(Object.keys(config.overlays),
cleanup: function cleanup(window) {
overlay.windows = overlay.windows.filter(w => w != window);
Cu.nukeSandbox(this.jsmodules);
},
unload: function unload(window) {

View File

@@ -247,6 +247,11 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
if (!("value" in prop) || !callable(prop.value) && !(k in item))
Object.defineProperty(item, k, prop);
function getWindow(obj) {
obj = Class.objectGlobal(obj);
return obj.window || obj;
}
let names = RealSet([name].concat(params.contains || []).map(e => "clear-" + e));
if (params.action)
storage.addObserver("sanitizer",
@@ -254,7 +259,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
if (names.has(event))
params.action.apply(params, arg);
},
Class.objectGlobal(params.action));
getWindow(params.action));
if (params.privateEnter || params.privateLeave)
storage.addObserver("private-mode",
@@ -263,7 +268,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
if (meth)
meth.call(params);
},
Class.objectGlobal(params.action));
getWindow(params.privateEnter || params.privateLeave));
},
observers: {

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.