const DS_EXTENSION_UUID = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}";
function DS_InitObserver()
{
 DS_UninstallObserver.register();
}

var DS_UninstallObserver = {
 _uninstall : false,
 observe : function(subject, topic, data)
 {
  if(topic == "em-action-requested")
  { 
   subject.QueryInterface(Components.interfaces.nsIUpdateItem);
   if(subject.id == EXTENSION_UUID)
   {
    if(data == "item-uninstalled")
    {
     this._uninstall = true;
    }
    else if(data == "item-cancel-action")
    {
     this._uninstall = false;
    }
   }
  }
  else if(topic == "quit-application-granted")
  {
   if(this._uninstall)
   {
    /* uninstall stuff. */
   }
   this.unregister();
  }
 },
 register : function()
 {
  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  observerService.addObserver(this, "em-action-requested", false);
  observerService.addObserver(this, "quit-application-granted", false);
 },
 unregister : function()
 {
  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
  observerService.removeObserver(this,"em-action-requested");
  observerService.removeObserver(this,"quit-application-granted");
 }
}

window.addEventListener("load", DS_InitObserver, false);

That is OK. It works well.