function undoClosed() {}

undoClosed.prototype = {

	observe: function(subject, topic, data)
	{
		if (topic == 'app-startup')
		{
			this.observerService = Components.classes['@mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService);
			this.observerService.addObserver(this, 'profile-after-change', false);
			this.observerService.addObserver(this, 'xpcom-shutdown', false);
		}
		else if (topic == 'profile-after-change')
		{
			var ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
			var styleSheetService = Components.classes['@mozilla.org/content/style-sheet-service;1'].getService(Components.interfaces.nsIStyleSheetService);
			var prefBranch = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch('extensions.undoclosedtabsbutton.');
			var prefs = prefBranch.getChildList('', {});
			for (var i = 0; i < prefs.length; i++)
			{
				if (prefBranch.getBoolPref(prefs[i]) && prefs[i].indexOf('.') == -1)
				{
					try
					{
						var sheet = ioService.newURI('chrome://undoclosedtabsbutton/skin/' + prefs[i] + '.css', null, null);
						styleSheetService.loadAndRegisterSheet(sheet, styleSheetService.AGENT_SHEET);
					}
					catch (ex)
					{
						prefBranch.clearUserPref(prefs[i]);
					}
				}
			}
		}
		else if (topic == 'xpcom-shutdown')
		{
			this.observerService.removeObserver(this, 'profile-after-change');
			this.observerService.removeObserver(this, 'xpcom-shutdown');
			this.observerService = null;
		}
	},
	
	QueryInterface: function(iid)
	{
		if (iid.equals(Components.interfaces.nsIObserver) || iid.equals(Components.interfaces.nsISupports))
		{
			return this;
		}
		else
		{
			throw Components.results.NS_ERROR_NO_INTERFACE;
		}
	}
}

var undoClosedModuleFactory = {

	NAME: 'undoclosedtabsbutton@supernova00.biz',
	
	CID: Components.ID('{9e7f8f70-2792-11db-a98b-0800200c9a66}'),
	
	CONTRACT_ID: '@supernova00.biz/undoclosedtabsbutton;1',
	
	IMPLEMENTATION: undoClosed,
	
	registerSelf: function(compMgr, fileSpec, location, type)
	{
		compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
		compMgr.registerFactoryLocation(this.CID, this.NAME, this.CONTRACT_ID, fileSpec, location, type);
		
		var categoryManager = Components.classes['@mozilla.org/categorymanager;1'].getService(Components.interfaces.nsICategoryManager);
		categoryManager.addCategoryEntry('app-startup', this.NAME, 'service,' + this.CONTRACT_ID, true, true);
	},
	
	unregisterSelf: function(compMgr, fileSpec, location)
	{
		compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
		compMgr.unregisterFactoryLocation(this.CID, fileSpec);
		
		var categoryManager = Components.classes['@mozilla.org/categorymanager;1'].getService(Components.interfaces.nsICategoryManager);
		categoryManager.deleteCategoryEntry('app-startup', this.NAME, true);
	},
	
	getClassObject: function(compMgr, cid, iid)
	{
		if (!iid.equals(Components.interfaces.nsIFactory))
		{
			throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
		}
		
		if (cid.equals(this.CID))
		{
			return this;
		}
		else
		{
			throw Components.results.NS_ERROR_NO_INTERFACE;
		}
	},
	
	canUnload: function(compMgr)
	{
		return true;
	},
	
	createInstance: function(outer, iid)
	{
		if (outer)
		{
			throw Components.results.NS_ERROR_NO_AGGREGATION;
		}
		
		return (new this.IMPLEMENTATION()).QueryInterface(iid);
	}
};

function NSGetModule(compMgr, fileSpec)
{
	return undoClosedModuleFactory;
}