Bug 452317 - FeedConverter.js: QueryInterface should throw NS_ERROR_NO_INTERFACE...
[wine-gecko.git] / extensions / jssh / nsJSShStarter.js
bloba0c1cc2b10becc369b90b53d8a1ea4de4c17af5c
1 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is the Mozilla JavaScript Shell project.
17 * The Initial Developer of the Original Code is
18 * Alex Fritze.
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Alex Fritze <alex@croczilla.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 try {
40 // this will only work pending bug#238324
41 importModule("resource:/jscodelib/JSComponentUtils.js");
43 catch(e) {
44 var ComponentUtils = {
45 generateFactory: function(ctor, interfaces) {
46 return {
47 createInstance: function(outer, iid) {
48 if (outer) throw Components.results.NS_ERROR_NO_AGGREGATION;
49 if (!interfaces)
50 return ctor().QueryInterface(iid);
51 for (var i=interfaces.length; i>=0; --i) {
52 if (iid.equals(interfaces[i])) break;
54 if (i<0 && !iid.equals(Components.interfaces.nsISupports))
55 throw Components.results.NS_ERROR_NO_INTERFACE;
56 return ctor();
61 generateNSGetModule: function(classArray, postRegister, preUnregister) {
62 var module = {
63 getClassObject: function(compMgr, cid, iid) {
64 if (!iid.equals(Components.interfaces.nsIFactory))
65 throw Components.results.NS_ERROR_NO_INTERFACE;
66 for (var i=0; i<classArray.length; ++i) {
67 if(cid.equals(classArray[i].cid))
68 return classArray[i].factory;
70 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
72 registerSelf: function(compMgr, fileSpec, location, type) {
73 debug("*** registering "+fileSpec.leafName+": [ ");
74 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
75 for (var i=0; i<classArray.length; ++i) {
76 debug(classArray[i].className+" ");
77 compMgr.registerFactoryLocation(classArray[i].cid,
78 classArray[i].className,
79 classArray[i].contractID,
80 fileSpec,
81 location,
82 type);
84 if (postRegister)
85 postRegister(compMgr, fileSpec, classArray);
86 debug("]\n");
88 unregisterSelf: function(compMgr, fileSpec, location) {
89 debug("*** unregistering "+fileSpec.leafName+": [ ");
90 if (preUnregister)
91 preUnregister(compMgr, fileSpec, classArray);
92 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
93 for (var i=0; i<classArray.length; ++i) {
94 debug(classArray[i].className+" ");
95 compMgr.unregisterFactoryLocation(classArray[i].cid, fileSpec);
97 debug("]\n");
99 canUnload: function(compMgr) {
100 return true;
104 return function(compMgr, fileSpec) {
105 return module;
109 get categoryManager() {
110 return Components.classes["@mozilla.org/categorymanager;1"]
111 .getService(Components.interfaces.nsICategoryManager);
116 //----------------------------------------------------------------------
117 // JSShStarter class
119 // constructor
120 function JSShStarter() {
123 JSShStarter.prototype = {
124 // nsICommandLineHandler methods:
125 handle : function(commandline) {
126 debug("JSShStarter: checking for -jssh startup option\n");
127 if (commandline.handleFlag("jssh", false)) {
128 // start a jssh server with startupURI
129 // "chrome://jssh/content/jssh-debug.js". We use 'getService'
130 // instead of 'createInstance' to get a well-known, globally
131 // accessible instance of a jssh-server.
132 // XXX Todo: get port, startupURI and loopbackOnly from prefs.
133 Components.classes["@mozilla.org/jssh-server;1"]
134 .getService(Components.interfaces.nsIJSShServer)
135 .startServerSocket(9997, "chrome://jssh/content/jssh-debug.js", true);
136 debug("JSShStarter: JSSh server started on port 9997\n");
140 helpInfo : " -jssh Start a JSSh server on port 9997.\n",
144 //----------------------------------------------------------------------
145 NSGetModule = ComponentUtils.generateNSGetModule(
148 className : "JSShStarter",
149 cid : Components.ID("28CA200A-C070-4454-AD47-551FBAE1C48C"),
150 contractID : "@mozilla.org/jssh-runner;1",
151 factory : ComponentUtils.generateFactory(function(){ return new JSShStarter();},
152 [Components.interfaces.nsICommandLineHandler])
155 function(mgr,file,arr) {
156 debug("register as command-line-handler");
157 ComponentUtils.categoryManager.addCategoryEntry("command-line-handler",
158 "a-jssh",
159 arr[0].contractID,
160 true, true);
162 function(mgr,file,arr) {
163 debug("unregister as command-line-handler");
164 ComponentUtils.categoryManager.deleteCategoryEntry("command-line-handler",
165 "a-jssh", true);