Bug 845863: Add a lookup for browser-scripts to allow loading a script only once. r=mbrubeck

--HG--
extra : rebase_source : 4eee7d026ead9cc1b3c5037efd20cda1e14c353f
This commit is contained in:
Sam Foster 2013-02-28 14:12:02 +00:00
parent fee019f92c
commit f8999bb34b

View File

@ -79,10 +79,10 @@ XPCOMUtils.defineLazyServiceGetter(this, "CrashReporter",
* so it is not possible to set a lazy getter for Geometry.jsm.
*/
Cu.import("resource://gre/modules/Geometry.jsm");
/*
* Browser scripts
*/
let ScriptContexts = {};
[
["WebProgress", "chrome://browser/content/WebProgress.js"],
["FindHelperUI", "chrome://browser/content/helperui/FindHelperUI.js"],
@ -134,12 +134,16 @@ Cu.import("resource://gre/modules/Geometry.jsm");
].forEach(function (aScript) {
let [name, script] = aScript;
XPCOMUtils.defineLazyGetter(window, name, function() {
let sandbox = {};
Services.scriptloader.loadSubScript(script, sandbox);
let sandbox;
if (script in ScriptContexts) {
sandbox = ScriptContexts[script];
} else {
sandbox = ScriptContexts[script] = {};
Services.scriptloader.loadSubScript(script, sandbox);
}
return sandbox[name];
});
});
#ifdef MOZ_SERVICES_SYNC
XPCOMUtils.defineLazyGetter(this, "Weave", function() {
Components.utils.import("resource://services-sync/main.js");