Bug 904927: Assign globals to "this" in modules so that they are available through the B2G module loader; r=Unfocused
authorIrving Reid <irving@mozilla.com>
Mon, 19 Aug 2013 11:03:12 -0400
changeset 143096 7287b269f6f28bee6169ec4a6dbaf3deccaf351f
parent 143095 02be3210e117aab6c12a29e8d3a80016fb3880f6
child 143097 04149d2dace694bf8c9a0013bd21567ffe495be9
push id25121
push userryanvm@gmail.com
push dateMon, 19 Aug 2013 21:02:23 +0000
treeherdermozilla-central@b7f636fada9f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs904927
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 904927: Assign globals to "this" in modules so that they are available through the B2G module loader; r=Unfocused
toolkit/mozapps/extensions/AddonLogging.jsm
toolkit/mozapps/extensions/DeferredSave.jsm
toolkit/mozapps/extensions/XPIProvider.jsm
toolkit/mozapps/extensions/XPIProviderUtils.js
--- a/toolkit/mozapps/extensions/AddonLogging.jsm
+++ b/toolkit/mozapps/extensions/AddonLogging.jsm
@@ -87,18 +87,18 @@ AddonLogger.prototype = {
     let stack = getStackDetails(aException);
 
     let consoleMessage = Cc["@mozilla.org/scripterror;1"].
                          createInstance(Ci.nsIScriptError);
     consoleMessage.init(message, stack.sourceName, null, stack.lineNumber, 0,
                         Ci.nsIScriptError.errorFlag, "component javascript");
     Services.console.logMessage(consoleMessage);
 
-    if (gDebugLogEnabled)
-      dump("*** " + message + "\n");
+    // Always dump errors, in case the Console Service isn't listening yet
+    dump("*** " + message + "\n");
 
     try {
       var tstamp = new Date();
       var logfile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_EXTENSIONS_LOG]);
       var stream = Cc["@mozilla.org/network/file-output-stream;1"].
                    createInstance(Ci.nsIFileOutputStream);
       stream.init(logfile, 0x02 | 0x08 | 0x10, LOGGER_FILE_PERM, 0); // write, create, append
       var writer = Cc["@mozilla.org/intl/converter-output-stream;1"].
--- a/toolkit/mozapps/extensions/DeferredSave.jsm
+++ b/toolkit/mozapps/extensions/DeferredSave.jsm
@@ -33,17 +33,17 @@ const DEFAULT_SAVE_DELAY_MS = 50;
  *        bytes it contains are written to the file as is.
  *        If aDataProvider returns a String the data are UTF-8 encoded
  *        and then written to the file.
  * @param [optional] aDelay
  *        The delay in milliseconds between the first saveChanges() call
  *        that marks the data as needing to be saved, and when the DeferredSave
  *        begins writing the data to disk. Default 50 milliseconds.
  */
-function DeferredSave(aPath, aDataProvider, aDelay) {
+this.DeferredSave = function (aPath, aDataProvider, aDelay) {
   // Set up loggers for this instance of DeferredSave
   let leafName = OS.Path.basename(aPath);
   Cu.import("resource://gre/modules/AddonLogging.jsm");
   LogManager.getLogger("DeferredSave/" + leafName, this);
 
   // @type {Deferred|null}, null when no data needs to be written
   // @resolves with the result of OS.File.writeAtomic when all writes complete
   // @rejects with the error from OS.File.writeAtomic if the write fails,
@@ -82,17 +82,17 @@ function DeferredSave(aPath, aDataProvid
   this._lastError = null;
 
   if (aDelay && (aDelay > 0))
     this._delay = aDelay;
   else
     this._delay = DEFAULT_SAVE_DELAY_MS;
 }
 
-DeferredSave.prototype = {
+this.DeferredSave.prototype = {
   get dirty() {
     return this._pending || this.writeInProgress;
   },
 
   get lastError() {
     return this._lastError;
   },
 
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -187,19 +187,20 @@ var gIDTest = /^(\{[0-9a-f]{8}-[0-9a-f]{
 
 
 const LAZY_OBJECTS = ["XPIDatabase"];
 
 var gLazyObjectsLoaded = false;
 
 function loadLazyObjects() {
   let scope = {};
+  scope.AddonInternal = AddonInternal;
+  scope.XPIProvider = XPIProvider;
   Services.scriptloader.loadSubScript("resource://gre/modules/XPIProviderUtils.js",
                                       scope);
-  scope.XPIProvider = XPIProvider;
 
   for (let name of LAZY_OBJECTS) {
     delete gGlobalScope[name];
     gGlobalScope[name] = scope[name];
   }
   gLazyObjectsLoaded = true;
   return scope;
 }
@@ -2798,18 +2799,20 @@ var XPIProvider = {
       // Load the manifest if necessary and sanity check the add-on ID
       try {
         if (!newAddon) {
           // Load the manifest from the add-on.
           let file = aInstallLocation.getLocationForID(aId);
           newAddon = loadManifestFromFile(file);
         }
         // The add-on in the manifest should match the add-on ID.
-        if (newAddon.id != aId)
-          throw new Error("Incorrect id in install manifest");
+        if (newAddon.id != aId) {
+          throw new Error("Invalid addon ID: expected addon ID " + aId +
+                          ", found " + newAddon.id + " in manifest");
+        }
       }
       catch (e) {
         WARN("Add-on is invalid", e);
 
         // Remove the invalid add-on from the install location if the install
         // location isn't locked, no restart will be necessary
         if (!aInstallLocation.locked)
           aInstallLocation.uninstallAddon(aId);
@@ -4241,17 +4244,16 @@ var XPIProvider = {
     AddonManagerPrivate.callAddonListeners("onOperationCancelled", wrapper);
 
     // Notify any other providers that this theme is now enabled again.
     if (aAddon.type == "theme" && aAddon.active)
       AddonManagerPrivate.notifyAddonChanged(aAddon.id, aAddon.type, false);
   }
 };
 
-
 function getHashStringForCrypto(aCrypto) {
   // return the two-digit hexadecimal code for a byte
   function toHexString(charCode)
     ("0" + charCode.toString(16)).slice(-2);
 
   // convert the binary hash data to a hex string.
   let binary = aCrypto.finish(false);
   return [toHexString(binary.charCodeAt(i)) for (i in binary)].join("").toLowerCase()
--- a/toolkit/mozapps/extensions/XPIProviderUtils.js
+++ b/toolkit/mozapps/extensions/XPIProviderUtils.js
@@ -7,16 +7,18 @@
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
+XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
+                                  "resource://gre/modules/AddonManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "AddonRepository",
                                   "resource://gre/modules/AddonRepository.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
                                   "resource://gre/modules/FileUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "DeferredSave",
                                   "resource://gre/modules/DeferredSave.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
                                   "resource://gre/modules/Promise.jsm");