mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-23 15:55:47 +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:
@@ -151,9 +151,13 @@ var Contexts = Module("contexts", {
|
|||||||
for each (let hive in values(this.groupList.slice()))
|
for each (let hive in values(this.groupList.slice()))
|
||||||
util.trapErrors("destroy", hive, "shutdown");
|
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))
|
if (plugin && "onUnload" in plugin && callable(plugin.onUnload))
|
||||||
util.trapErrors("onUnload", plugin);
|
util.trapErrors("onUnload", plugin);
|
||||||
|
|
||||||
|
if (isinstance(plugin, ["Sandbox"]))
|
||||||
|
util.trapErrors("nukeSandbox", Cu, plugin);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
signals: {
|
signals: {
|
||||||
|
|||||||
@@ -89,12 +89,30 @@ var Modules = function Modules(window) {
|
|||||||
Module.list = [];
|
Module.list = [];
|
||||||
Module.constructors = {};
|
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/"];
|
const BASES = [BASE, "resource://dactyl-local-content/"];
|
||||||
|
|
||||||
jsmodules = Cu.createObjectIn(window);
|
jsmodules = newContext(window, false, "Dactyl `jsmodules`");
|
||||||
jsmodules.NAME = "jsmodules";
|
jsmodules.NAME = "jsmodules";
|
||||||
|
|
||||||
|
const create = bind("create", jsmodules.Object);
|
||||||
|
|
||||||
const modules = update(create(jsmodules), {
|
const modules = update(create(jsmodules), {
|
||||||
yes_i_know_i_should_not_report_errors_in_these_branches_thanks: [],
|
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) {
|
newContext: newContext,
|
||||||
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;
|
|
||||||
},
|
|
||||||
|
|
||||||
get ownPropertyValues() array.compact(
|
get ownPropertyValues() array.compact(
|
||||||
Object.getOwnPropertyNames(this)
|
Object.getOwnPropertyNames(this)
|
||||||
@@ -166,6 +170,7 @@ overlay.overlayWindow(Object.keys(config.overlays),
|
|||||||
const modules = Modules(window);
|
const modules = Modules(window);
|
||||||
modules.moduleManager = this;
|
modules.moduleManager = this;
|
||||||
this.modules = modules;
|
this.modules = modules;
|
||||||
|
this.jsmodules = modules.jsmodules;
|
||||||
|
|
||||||
window.dactyl = { modules: modules };
|
window.dactyl = { modules: modules };
|
||||||
|
|
||||||
@@ -225,6 +230,8 @@ overlay.overlayWindow(Object.keys(config.overlays),
|
|||||||
|
|
||||||
cleanup: function cleanup(window) {
|
cleanup: function cleanup(window) {
|
||||||
overlay.windows = overlay.windows.filter(w => w != window);
|
overlay.windows = overlay.windows.filter(w => w != window);
|
||||||
|
|
||||||
|
Cu.nukeSandbox(this.jsmodules);
|
||||||
},
|
},
|
||||||
|
|
||||||
unload: function unload(window) {
|
unload: function unload(window) {
|
||||||
|
|||||||
@@ -247,6 +247,11 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
|||||||
if (!("value" in prop) || !callable(prop.value) && !(k in item))
|
if (!("value" in prop) || !callable(prop.value) && !(k in item))
|
||||||
Object.defineProperty(item, k, prop);
|
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));
|
let names = RealSet([name].concat(params.contains || []).map(e => "clear-" + e));
|
||||||
if (params.action)
|
if (params.action)
|
||||||
storage.addObserver("sanitizer",
|
storage.addObserver("sanitizer",
|
||||||
@@ -254,7 +259,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
|||||||
if (names.has(event))
|
if (names.has(event))
|
||||||
params.action.apply(params, arg);
|
params.action.apply(params, arg);
|
||||||
},
|
},
|
||||||
Class.objectGlobal(params.action));
|
getWindow(params.action));
|
||||||
|
|
||||||
if (params.privateEnter || params.privateLeave)
|
if (params.privateEnter || params.privateLeave)
|
||||||
storage.addObserver("private-mode",
|
storage.addObserver("private-mode",
|
||||||
@@ -263,7 +268,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
|
|||||||
if (meth)
|
if (meth)
|
||||||
meth.call(params);
|
meth.call(params);
|
||||||
},
|
},
|
||||||
Class.objectGlobal(params.action));
|
getWindow(params.privateEnter || params.privateLeave));
|
||||||
},
|
},
|
||||||
|
|
||||||
observers: {
|
observers: {
|
||||||
|
|||||||
@@ -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
|
// This work is licensed for reuse under an MIT license. Details are
|
||||||
// given in the LICENSE.txt file included with this file.
|
// given in the LICENSE.txt file included with this file.
|
||||||
|
|||||||
Reference in New Issue
Block a user