diff --git a/chrome/chromeFiles/content/scholar/xpcom/scholar.js b/chrome/chromeFiles/content/scholar/xpcom/scholar.js index 40ba353cc1..db602e4032 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/scholar.js +++ b/chrome/chromeFiles/content/scholar/xpcom/scholar.js @@ -14,10 +14,12 @@ const SCHOLAR_CONFIG = { */ var Scholar = new function(){ var _initialized = false; + var _shutdown = false; var _localizedStringBundle; // Privileged (public) methods this.init = init; + this.shutdown = shutdown; this.getProfileDirectory = getProfileDirectory; this.getScholarDirectory = getScholarDirectory; this.getStorageDirectory = getStorageDirectory; @@ -42,6 +44,15 @@ var Scholar = new function(){ return false; } + // Register shutdown handler to call Scholar.shutdown() + var observerService = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + observerService.addObserver({ + observe: function(subject, topic, data){ + Scholar.shutdown(subject, topic, data) + } + }, "xpcom-shutdown", false); + // Load in the preferences branch for the extension Scholar.Prefs.init(); @@ -75,6 +86,16 @@ var Scholar = new function(){ } + function shutdown(subject, topic, data){ + // Called twice otherwise, for some reason + if (_shutdown){ + return false; + } + + _shutdown = true; + } + + function getProfileDirectory(){ return Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties)