sbPlaylistHandlerModule.js
Go to the documentation of this file.
1 
32 const Cc = Components.classes;
33 const Ci = Components.interfaces;
34 const Cr = Components.results;
35 
36 var componentInitRun = false;
37 
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 
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) {
200 }
201 
var componentInitRun
SafebrowsingApplicationMod prototype registerSelf
sidebarFactory createInstance
Definition: nsSidebar.js:351
sbOSDControlService prototype QueryInterface
SafebrowsingApplicationMod prototype getClassObject
DataRemote prototype constructor
return null
Definition: FeedWriter.js:1143
function NSGetModule(compMgr, fileSpec)
var sbPlaylistHandlerModule
if(DEBUG_DATAREMOTES)
var iosvc
_getSelectedPageStyle s i
const componentData