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
15 * The Original Code is the Mozilla JavaScript Shell project.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2003
20 * the Initial Developer. All Rights Reserved.
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 ***** */
40 // this will only work pending bug#238324
41 importModule("resource:/jscodelib/JSComponentUtils.js");
44 var ComponentUtils
= {
45 generateFactory: function(ctor
, interfaces
) {
47 createInstance: function(outer
, iid
) {
48 if (outer
) throw Components
.results
.NS_ERROR_NO_AGGREGATION
;
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
;
61 generateNSGetModule: function(classArray
, postRegister
, preUnregister
) {
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
,
85 postRegister(compMgr
, fileSpec
, classArray
);
88 unregisterSelf: function(compMgr
, fileSpec
, location
) {
89 debug("*** unregistering "+fileSpec
.leafName
+": [ ");
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
);
99 canUnload: function(compMgr
) {
104 return function(compMgr
, fileSpec
) {
109 get categoryManager() {
110 return Components
.classes
["@mozilla.org/categorymanager;1"]
111 .getService(Components
.interfaces
.nsICategoryManager
);
116 //----------------------------------------------------------------------
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",
162 function(mgr
,file
,arr
) {
163 debug("unregister as command-line-handler");
164 ComponentUtils
.categoryManager
.deleteCategoryEntry("command-line-handler",