svnno****@sourc*****
svnno****@sourc*****
2007年 8月 15日 (水) 23:36:12 JST
Revision: 201 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=bbs2ch&view=rev&rev=201 Author: flyson Date: 2007-08-15 23:36:11 +0900 (Wed, 15 Aug 2007) Log Message: ----------- content-policy に動的に登録するようにした Modified Paths: -------------- trunk/bbs2chreader/components/b2rThreadRedirector.js Modified: trunk/bbs2chreader/components/b2rThreadRedirector.js =================================================================== --- trunk/bbs2chreader/components/b2rThreadRedirector.js 2007-08-13 14:48:40 UTC (rev 200) +++ trunk/bbs2chreader/components/b2rThreadRedirector.js 2007-08-15 14:36:11 UTC (rev 201) @@ -59,22 +59,39 @@ .getService(Components.interfaces.nsIPrefBranch2); this._enabled = this._pref.getBoolPref(this._PREF_ENABLED); - this._pref.addObserver(this._PREF_ENABLED, this, false); - this._observerService.addObserver(this, "xpcom-shutdown", false); }, // ********** ********* implements nsIObserver ********** ********** observe: function(aSubject, aTopic, aData){ - if(aTopic == "xpcom-shutdown"){ - this._pref.removeObserver(this._PREF_ENABLED, this); - this._observerService.removeObserver(this, "xpcom-shutdown"); + switch(aTopic){ + case "app-startup": + this._pref.addObserver(this._PREF_ENABLED, this, false); + this._observerService.addObserver(this, "xpcom-shutdown", false); + this._observerService.addObserver(this, "profile-after-change", false); + break; - }else if(aTopic == "nsPref:changed"){ - if(aData == this._PREF_ENABLED){ - this._enabled = this._pref.getBoolPref(this._PREF_ENABLED); - } + case "xpcom-shutdown": + this._pref.removeObserver(this._PREF_ENABLED, this); + this._observerService.removeObserver(this, "xpcom-shutdown"); + break; + + case "profile-after-change": + if(this._enabled){ + var categoryManager = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + categoryManager.addCategoryEntry("content-policy", ComponentModule.CONTRACTID, + ComponentModule.CONTRACTID, true, true); + } + this._observerService.removeObserver(this, "profile-after-change"); + break; + + case "nsPref:changed": + if(aData == this._PREF_ENABLED){ + this._enabled = this._pref.getBoolPref(this._PREF_ENABLED); + } + break; } }, @@ -163,6 +180,7 @@ QueryInterface: function(aIID){ if(aIID.equals(Components.interfaces.nsIContentPolicy)) return this; if(aIID.equals(Components.interfaces.nsISupportsWeakReference)) return this; + if(aIID.equals(Components.interfaces.nsIObserver)) return this; if(aIID.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_ERROR_NO_INTERFACE; @@ -185,6 +203,8 @@ return this.getInstance(aIID); if(aIID.equals(Components.interfaces.nsISupportsWeakReference)) return this.getInstance(aIID); + if(aIID.equals(Components.interfaces.nsIObserver)) + return this.getInstance(aIID); if(aIID.equals(Components.interfaces.nsISupports)) return this.getInstance(aIID); @@ -219,8 +239,9 @@ var categoryManager = Components.classes["@mozilla.org/categorymanager;1"] .getService(Components.interfaces.nsICategoryManager); - categoryManager.addCategoryEntry("content-policy", this.CONTRACTID, + categoryManager.addCategoryEntry("app-startup", this.CONTRACTID, this.CONTRACTID, true, true); + }, @@ -230,7 +251,7 @@ var categoryManager = Components.classes["@mozilla.org/categorymanager;1"] .getService(Components.interfaces.nsICategoryManager); - categoryManager.deleteCategoryEntry("content-policy", this.CONTRACTID, true); + categoryManager.deleteCategoryEntry("app-startup", this.CONTRACTID, true); },