about:startup - address Mossop's review comment
authorDaniel Brooks <db48x@db48x.net>
Mon, 25 Oct 2010 16:39:05 -0500
changeset 58865 a62968ad14d1b49d85d582202e6fd753b2ce579e
parent 58864 c6e28dd6326cdf7c76813783c896adbcc38a1e7f
child 58866 2ba79a29163e8c2463a9335d5c8d65fd87da164b
push idunknown
push userunknown
push dateunknown
milestone2.0b8pre
about:startup - address Mossop's review comment
toolkit/content/aboutStartup.js
toolkit/mozapps/extensions/AddonManager.jsm
xpcom/system/nsIXULRuntime.idl
--- a/toolkit/content/aboutStartup.js
+++ b/toolkit/content/aboutStartup.js
@@ -41,19 +41,28 @@ Components.utils.import("resource://gre/
 
 let strings = Services.strings.createBundle("chrome://global/locale/aboutStartup.properties");
 let branding = Services.strings.createBundle("chrome://branding/locale/brand.properties");
 let brandShortName = branding.GetStringFromName("brandShortName");
 
 function displayTimestamp(id, µs) document.getElementById(id).textContent = formatstamp(µs);
 function displayDuration(id, µs) document.getElementById(id).nextSibling.textContent = formatms(msFromµs(µs));
 
-function formatStr(str, args) strings.formatStringFromName("about.startup."+ str, args, args.length);
+function formatStr(str, args)
+{
+  try {
+    return strings.formatStringFromName("about.startup."+ str, args, args.length);
+  } catch (x) {
+    return str +" "+ args.toSource();
+  }
+}
 function appVersion(version, build) formatStr("appVersion", [brandShortName, version, build]);
-function formatExtension(str, name, version) formatStr("extension"+str, [name, version]);
+function formatExtension(str, name, version) formatStr("extension"+(str.replace(/^on/, "")
+                                                                                                 .replace(/ing$/, "ed")),
+                                                                            [name, version]);
 
 function msFromµs(µs) µs / 1000;
 function formatstamp(µs) new Date(msFromµs(µs));
 function formatµs(µs) µs + " µs";
 function formatms(ms) formatStr("milliseconds", [ms]);
 
 function point(stamp, µs, v, b) [msFromµs(stamp), msFromµs(µs), { appVersion: v, appBuild: b }];
 function range(a, b) ({ from: msFromµs(a), to: msFromµs(b || a) });
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -223,18 +223,16 @@ var AddonManagerInternal = {
   /**
    * Initializes the AddonManager, loading any known providers and initializing
    * them.
    */
   startup: function AMI_startup() {
     if (gStarted)
       return;
 
-    this._addNotificationListeners();
-
     let appChanged = undefined;
 
     try {
       appChanged = Services.appinfo.version !=
                    Services.prefs.getCharPref(PREF_EM_LAST_APP_VERSION);
     }
     catch (e) { }
 
@@ -433,16 +431,22 @@ var AddonManagerInternal = {
       try {
         if (aMethod in listener)
           listener[aMethod].apply(listener, args);
       }
       catch (e) {
         WARN("AddonListener threw exception when calling " + aMethod + ": " + e);
       }
     });
+    let bag = Cc["@mozilla.org/hash-property-bag;1"]
+                .createInstance(Ci.nsIWritablePropertyBag2);
+    bag.setPropertyAsAString("id", args[0].id);
+    bag.setPropertyAsAString("name", args[0].name);
+    bag.setPropertyAsAString("version", args[0].version);
+    Services.obs.notifyObservers(bag, "AddonManager-event", aMethod);
   },
 
   /**
    * Notifies all providers that an add-on has been enabled when that type of
    * add-on only supports a single add-on being enabled at a time. This allows
    * the providers to disable theirs if necessary.
    *
    * @param  aId
@@ -857,43 +861,17 @@ var AddonManagerInternal = {
     }
   },
 
   get autoUpdateDefault() {
     try {
       return Services.prefs.getBoolPref(PREF_EM_AUTOUPDATE_DEFAULT);
     } catch(e) { }
     return true;
-  },
-
-  /**
-   * Adds an AddonListener that uses the observer service to notify
-   * native code of the extension events.
-   *
-   * Currently only handles that subset of the events and data that
-     * the about:startup page requires.
-   *
-   */
-  _addNotificationListeners: function()
-  {
-    function notify(msg, extension)
-    {
-      let bag = Cc["@mozilla.org/hash-property-bag;1"]
-                  .createInstance(Ci.nsIWritablePropertyBag2);
-      bag.setPropertyAsAString("id", extension.id);
-      bag.setPropertyAsAString("name", extension.name);
-      bag.setPropertyAsAString("version", extension.version);
-      Services.obs.notifyObservers(bag, "AddonManager-event", msg);
-    }
-    this.addAddonListener({ onEnabling: function(extension) { notify("Enabled", extension) },
-                            onDisabling: function(extension) { notify("Disabled", extension) },
-                            onInstalling: function(extension) { notify("Installed", extension) },
-                            onUninstalling: function(extension) { notify("Uninstalled", extension) },
-                          });
-  },
+  }
 };
 
 /**
  * Should not be used outside of core Mozilla code. This is a private API for
  * the startup and platform integration code to use. Refer to the methods on
  * AddonManagerInternal for documentation however note that these methods are
  * subject to change at any time.
  */
--- a/xpcom/system/nsIXULRuntime.idl
+++ b/xpcom/system/nsIXULRuntime.idl
@@ -103,17 +103,16 @@ interface nsIXULRuntime : nsISupports
 
   /**
    * Signal the apprunner to invalidate caches on the next restart.
    * This will cause components to be autoregistered and all
    * fastload data to be re-created.
    */
   void invalidateCachesOnRestart();
 
-
   /**
    * Recorded timestamp indicating when the operating system began launching the app
     */
   readonly attribute unsigned long long launchTimestamp;
 
   /**
    * Recorded timestamp indicating when app startup began (essentially XRE_Main)
     */