home *** CD-ROM | disk | FTP | other *** search
/ Freelog 100 / FreelogNo100-NovembreDecembre2010.iso / Multimedia / Songbird / Songbird_1.8.0-1800_windows-i686-msvc8.exe / components / sbPlaylistHandlerModule.js < prev    next >
Text File  |  2010-08-30  |  6KB  |  202 lines

  1. /**
  2. //
  3. // BEGIN SONGBIRD GPL
  4. // 
  5. // This file is part of the Songbird web player.
  6. //
  7. // Copyright(c) 2005-2008 POTI, Inc.
  8. // http://songbirdnest.com
  9. // 
  10. // This file may be licensed under the terms of of the
  11. // GNU General Public License Version 2 (the "GPL").
  12. // 
  13. // Software distributed under the License is distributed 
  14. // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
  15. // express or implied. See the GPL for the specific language 
  16. // governing rights and limitations.
  17. //
  18. // You should have received a copy of the GPL along with this 
  19. // program. If not, go to http://www.gnu.org/licenses/gpl.html
  20. // or write to the Free Software Foundation, Inc., 
  21. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. // 
  23. // END SONGBIRD GPL
  24. //
  25.  */
  26.  
  27. /**
  28.  * \file sbPlaylistHandlerModule.js
  29.  * \brief Based on http://mxr.mozilla.org/seamonkey/source/calendar/base/src/calItemModule.js
  30.  */
  31.  
  32. const Cc = Components.classes;
  33. const Ci = Components.interfaces;
  34. const Cr = Components.results;
  35.  
  36. var componentInitRun = false;
  37.  
  38. const componentData =
  39.   [
  40.     {cid: null,
  41.      contractid: null,
  42.      script: "sbPlaylistHandlerUtils.js",
  43.      constructor: null},
  44.  
  45.    {cid: Components.ID("{ba32eac9-6732-4d5d-be50-156f52b5368b}"),
  46.      contractid: "@songbirdnest.com/Songbird/Playlist/Reader/M3U;1",
  47.      script: "sbM3UPlaylistHandler.js",
  48.      constructor: "sbM3UPlaylistHandler",
  49.      category: "playlist-reader",
  50.      categoryEntry: "m3u"},
  51.  
  52.    {cid: Components.ID("{a6937260-0d7f-4721-8f31-4b8455cf72c9}"),
  53.      contractid: "@songbirdnest.com/Songbird/Playlist/Reader/PLS;1",
  54.      script: "sbPLSPlaylistHandler.js",
  55.      constructor: "sbPLSPlaylistHandler",
  56.      category: "playlist-reader",
  57.      categoryEntry: "pls"},
  58.  
  59.    {cid: Components.ID("{fc67054f-3a60-4d8e-a2ec-fc1c8feac14c}"),
  60.      contractid: "@songbirdnest.com/Songbird/Playlist/Reader/Feed;1",
  61.      script: "sbFeedPlaylistHandler.js",
  62.      constructor: "sbFeedPlaylistHandler",
  63.      category: "playlist-reader",
  64.      categoryEntry: "feed"},
  65.  
  66.    {cid: Components.ID("{75c8f646-e75a-4743-89cd-412fa083ce07}"),
  67.      contractid: "@songbirdnest.com/Songbird/Playlist/Reader/HTML;1",
  68.      script: "sbHTMLPlaylistHandler.js",
  69.      constructor: "sbHTMLPlaylistHandler",
  70.      category: "playlist-reader",
  71.      categoryEntry: "html"},
  72.      
  73.    {cid: Components.ID("{e2eeb4bd-85b2-4eda-8a7c-90ad7f04957c}"),
  74.      contractid: "@songbirdnest.com/Songbird/Playlist/Reader/ASX;1",
  75.      script: "sbASXPlaylistHandler.js",
  76.      constructor: "sbASXPlaylistHandler",
  77.      category: "playlist-reader",
  78.      categoryEntry: "asx"}
  79.   ];
  80.  
  81. var sbPlaylistHandlerModule = {
  82.   mScriptsLoaded: false,
  83.   loadScripts: function () {
  84.     if (this.mScriptsLoaded)
  85.       return;
  86.  
  87.     const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
  88.     const jssslIID = Ci.mozIJSSubScriptLoader;
  89.  
  90.     const dirsvcContractID = "@mozilla.org/file/directory_service;1";
  91.     const propsIID = Ci.nsIProperties;
  92.  
  93.     const iosvcContractID = "@mozilla.org/network/io-service;1";
  94.     const iosvcIID = Ci.nsIIOService;
  95.  
  96.     var loader = Cc[jssslContractID].getService(jssslIID);
  97.     var dirsvc = Cc[dirsvcContractID].getService(propsIID);
  98.     var iosvc = Cc[iosvcContractID].getService(iosvcIID);
  99.  
  100.     // Note that unintuitively, __LOCATION__.parent == .
  101.     // We expect to find the subscripts in ./../js
  102.     var appdir = __LOCATION__.parent.parent;
  103.     appdir.append("scripts");
  104.  
  105.     for (var i = 0; i < componentData.length; i++) {
  106.       var scriptName = componentData[i].script;
  107.       if (!scriptName)
  108.         continue;
  109.  
  110.       var f = appdir.clone();
  111.       f.append(scriptName);
  112.  
  113.       try {
  114.         var fileurl = iosvc.newFileURI(f);
  115.         loader.loadSubScript(fileurl.spec, null);
  116.       }
  117.       catch (e) {
  118.         dump("Error while loading " + fileurl.spec + "\n");
  119.         throw e;
  120.       }
  121.     }
  122.  
  123.     this.mScriptsLoaded = true;
  124.   },
  125.  
  126.   registerSelf: function (compMgr, fileSpec, location, type) {
  127.     compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
  128.  
  129.     var catman = Cc["@mozilla.org/categorymanager;1"]
  130.                    .getService(Ci.nsICategoryManager);
  131.     for (var i = 0; i < componentData.length; i++) {
  132.       var comp = componentData[i];
  133.       if (!comp.cid)
  134.         continue;
  135.       compMgr.registerFactoryLocation(comp.cid,
  136.                                       "",
  137.                                       comp.contractid,
  138.                                       fileSpec,
  139.                                       location,
  140.                                       type);
  141.  
  142.       if (comp.category) {
  143.         var contractid;
  144.         if (comp.service)
  145.           contractid = "service," + comp.contractid;
  146.         else
  147.           contractid = comp.contractid;
  148.         catman.addCategoryEntry(comp.category, comp.categoryEntry,
  149.                                 contractid, true, true);
  150.       }
  151.     }
  152.   },
  153.  
  154.   makeFactoryFor: function(constructor) {
  155.     var factory = {
  156.       QueryInterface: function (aIID) {
  157.         if (!aIID.equals(Ci.nsISupports) &&
  158.             !aIID.equals(Ci.nsIFactory))
  159.             throw Cr.NS_ERROR_NO_INTERFACE;
  160.         return this;
  161.       },
  162.  
  163.       createInstance: function(outer, iid) {
  164.         if (outer != null)
  165.           throw Cr.NS_ERROR_NO_AGGREGATION;
  166.         return (new constructor()).QueryInterface(iid);
  167.       }
  168.     };
  169.  
  170.     return factory;
  171.   },
  172.  
  173.   getClassObject: function(compMgr, cid, iid) {
  174.     if (!iid.equals(Ci.nsIFactory))
  175.       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
  176.  
  177.     if (!this.mScriptsLoaded)
  178.       this.loadScripts();
  179.  
  180.     for (var i = 0; i < componentData.length; i++) {
  181.       if (cid.equals(componentData[i].cid)) {
  182.         if (componentData[i].onComponentLoad) {
  183.           eval(componentData[i].onComponentLoad);
  184.         }
  185.         // eval to get usual scope-walking
  186.         return this.makeFactoryFor(eval(componentData[i].constructor));
  187.       }
  188.     }
  189.  
  190.     throw Cr.NS_ERROR_NO_INTERFACE;
  191.   },
  192.  
  193.   canUnload: function(compMgr) {
  194.     return true;
  195.   }
  196. };
  197.  
  198. function NSGetModule(compMgr, fileSpec) {
  199.   return sbPlaylistHandlerModule;
  200. }
  201.  
  202.