I've been searching all over the web for answers on this and I am not having any luck.
My question is this: My plugin has a cleanup-on-uninstall routine that I want to run. It is currently set to listen via observer-service for the topic "quit-application-granted". I am trying to get this to fire at the earliest opportunity that we know Firefox is quitting, as having the plugin uninstall itself and then another plugin aborting the shutdown would cause unpredictable behavior.
Here's the relevant code:
Code: Select all
////////////////////////////////////////////////////////////////////////////////
// extension uninstallation cleanup and quit notification
////////////////////////////////////////////////////////////////////////////////
const OBS_QUIT_REQUEST = "quit-application-requested";
const OBS_QUIT_GRANTED = "quit-application-granted";
const OBS_ACTION_REQUESTED = "em-action-requested";
function globalEventObserver() {
this.register()
}
globalEventObserver.prototype = {
observe: function(subject, topic, data) {
dprint("globalEventObserver: Observed something (T=" + topic + ", S=" + subject.id + ", D=" + data + ")");
if (topic == OBS_ACTION_REQUSTED) {
subject.QueryInterface(Components.interfaces.nsIUpdateItem);
if (subject.id == ddFirefoxID) {
if (data == "item-uninstalled") {
nukePrefs = true;
dprint("globalEventObserver: User wants to uninstall me...");
} else if (data == "item-cancel-action") {
nukePrefs = false;
dprint("globalEventObserver: User cancelled uninstall request.");
}
}
} else if (topic == OBS_QUIT_REQUEST) {
dprint("globalEventObserver: got program exit request!");
abortSeti = true;
} else if (topic == OBS_QUIT_GRANTED) {
if (ddFirefoxUninstallOnExit) {
var ourprefs = prefs.getBranch(prefprefix);
var newpre = prefprefix.substring(0, prefprefix.length - 1);
dprint("Removing all preferences under " & newpre);
prefs.deleteBranch(newpre, "");
}
}
},
register: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, OBS_ACTION_REQUSTED, false);
observerService.addObserver(this, OBS_QUIT_REQUEST, false);
observerService.addObserver(this, OBS_QUIT_GRANTED, false);
},
unregister: function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this, OBS_ACTION_REQEUST);
observerService.removeObserver(this, OBS_QUIT_REQUEST);
observerService.removeObserver(this, OBS_QUIT_GRANTED);
}
}
The quit-application-requested code shuts down a background process that blocks FF from exiting, but as I said before it's abortable -- so I don't want this plugin uninstalling itself should the shutdown be aborted. Why is quit-application-granted not firing?
Thanks for your help. I spied one other thread here concerning this issue, but it didn't answer anything.
-Tom