diff --git a/dom/apps/Webapps.jsm b/dom/apps/Webapps.jsm index 1c537d2e979e..61706dd847d3 100644 --- a/dom/apps/Webapps.jsm +++ b/dom/apps/Webapps.jsm @@ -203,6 +203,7 @@ this.DOMApplicationRegistry = { dirKey: DIRECTORY_NAME, init: function() { + // Keep the messages in sync with the lazy-loading in browser.js (bug 1171013). this.messages = ["Webapps:Install", "Webapps:Uninstall", "Webapps:GetSelf", diff --git a/js/xpconnect/loader/XPCOMUtils.jsm b/js/xpconnect/loader/XPCOMUtils.jsm index a3287ab408f1..cbe232da5e95 100644 --- a/js/xpconnect/loader/XPCOMUtils.jsm +++ b/js/xpconnect/loader/XPCOMUtils.jsm @@ -231,7 +231,9 @@ this.XPCOMUtils = { /** * Defines a getter on a specified object for a module. The module will not - * be imported until first use. + * be imported until first use. The getter allows to execute setup and + * teardown code (e.g. to register/unregister to services) and accepts + * a proxy object which acts on behalf of the module until it is imported. * * @param aObject * The object to define the lazy getter on. @@ -242,15 +244,35 @@ this.XPCOMUtils = { * @param aSymbol * The name of the symbol exported by the module. * This parameter is optional and defaults to aName. + * @param aPreLambda + * A function that is executed when the proxy is set up. + * This will only ever be called once. + * @param aPostLambda + * A function that is executed when the module has been imported to + * run optional teardown procedures on the proxy object. + * This will only ever be called once. + * @param aProxy + * An object which acts on behalf of the module to be imported until + * the module has been imported. */ - defineLazyModuleGetter: function XPCU_defineLazyModuleGetter(aObject, aName, - aResource, - aSymbol) + defineLazyModuleGetter: function XPCU_defineLazyModuleGetter( + aObject, aName, aResource, aSymbol, + aPreLambda, aPostLambda, aProxy) { + let proxy = aProxy || {}; + + if (typeof(aPreLambda) === "function") { + aPreLambda.apply(proxy); + } + this.defineLazyGetter(aObject, aName, function XPCU_moduleLambda() { var temp = {}; try { Cu.import(aResource, temp); + + if (typeof(aPostLambda) === "function") { + aPostLambda.apply(proxy); + } } catch (ex) { Cu.reportError("Failed to load module " + aResource + "."); throw ex;