2000-08-05 21:19:44 +04:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Seth Spitzer <sspitzer@netscape.com>
|
|
|
|
* Robert Ginda <rginda@netscape.com>
|
|
|
|
* R. Saravanan <svn@xmlterm.org>
|
|
|
|
*/
|
|
|
|
|
2000-07-07 18:44:26 +04:00
|
|
|
/*
|
|
|
|
* This file contains the following xmlterm related components:
|
|
|
|
* 1. Command line handler service, for responding to the -terminal command line
|
|
|
|
* option. (CLineHandler)
|
|
|
|
* 2. Content handler for responding to content of type x-application-telnet
|
|
|
|
* (TelnetContentHandler)
|
|
|
|
* 3. Protocol handler for supplying a channel to the browser when an telnet://
|
|
|
|
* link is clicked. (TelnetProtocolHandler)
|
|
|
|
* 4. A (nearly empty) imeplementation of nsIChannel for telling the browser
|
|
|
|
* that telnet:// links have the content type x-application-telnet (BogusChannel)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* components defined in this file */
|
2000-09-14 03:57:52 +04:00
|
|
|
const CLINE_SERVICE_CONTRACTID =
|
|
|
|
"@mozilla.org/commandlinehandler/general-startup;1?type=terminal";
|
2000-07-07 18:44:26 +04:00
|
|
|
const CLINE_SERVICE_CID =
|
|
|
|
Components.ID("{0eb82bE0-43a2-11d3-8e76-006008948af5}");
|
2000-09-14 03:57:52 +04:00
|
|
|
const TELNETCNT_HANDLER_CONTRACTID =
|
|
|
|
"@mozilla.org/uriloader/content-handler;1?type=x-application-telnet";
|
2000-07-07 18:44:26 +04:00
|
|
|
const TELNETCNT_HANDLER_CID =
|
|
|
|
Components.ID("{0eb82bE1-43a2-11d3-8e76-006008948af5}");
|
2000-09-14 03:57:52 +04:00
|
|
|
const TELNETPROT_HANDLER_CONTRACTID =
|
|
|
|
"@mozilla.org/network/protocol;1?name=telnet";
|
2000-07-07 18:44:26 +04:00
|
|
|
const TELNETPROT_HANDLER_CID =
|
|
|
|
Components.ID("{0eb82bE2-43a2-11d3-8e76-006008948af5}");
|
|
|
|
|
|
|
|
/* components used in this file */
|
2000-09-14 03:57:52 +04:00
|
|
|
const MEDIATOR_CONTRACTID =
|
|
|
|
"@mozilla.org/rdf/datasource;1?name=window-mediator"
|
|
|
|
const SIMPLEURI_CONTRACTID =
|
|
|
|
"@mozilla.org/network/simple-uri;1";
|
|
|
|
const ASS_CONTRACTID =
|
|
|
|
"@mozilla.org/appshell/appShellService;1";
|
2000-09-24 18:22:11 +04:00
|
|
|
const SCRIPTSECURITYMANAGER_CONTRACTID =
|
|
|
|
"@mozilla.org/scriptsecuritymanager;1";
|
|
|
|
const NS_IOSERVICE_CID_STR =
|
|
|
|
"{9ac9e770-18bc-11d3-9337-00104ba0fd40}";
|
2000-07-07 18:44:26 +04:00
|
|
|
|
2000-09-24 18:22:11 +04:00
|
|
|
/* interfaces used in this file */
|
2000-07-07 18:44:26 +04:00
|
|
|
const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
|
|
|
|
const nsICmdLineHandler = Components.interfaces.nsICmdLineHandler;
|
|
|
|
const nsICategoryManager = Components.interfaces.nsICategoryManager;
|
|
|
|
const nsIContentHandler = Components.interfaces.nsIContentHandler;
|
|
|
|
const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
|
|
|
|
const nsIURI = Components.interfaces.nsIURI;
|
|
|
|
const nsIChannel = Components.interfaces.nsIChannel;
|
|
|
|
const nsIRequest = Components.interfaces.nsIRequest;
|
|
|
|
const nsIAppShellService = Components.interfaces.nsIAppShellService;
|
2000-09-24 18:22:11 +04:00
|
|
|
const nsIIOService = Components.interfaces.nsIIOService;
|
|
|
|
const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
|
2000-07-07 18:44:26 +04:00
|
|
|
const nsISupports = Components.interfaces.nsISupports;
|
|
|
|
|
|
|
|
/* Command Line handler service */
|
|
|
|
function CLineService()
|
|
|
|
{}
|
|
|
|
|
|
|
|
CLineService.prototype.commandLineArgument = "-terminal";
|
|
|
|
CLineService.prototype.prefNameForStartup = "general.startup.terminal";
|
|
|
|
CLineService.prototype.chromeUrlForTask="chrome://xmlterm/content";
|
|
|
|
CLineService.prototype.helpText = "Start with a command line terminal";
|
|
|
|
CLineService.prototype.handlesArgs=false;
|
|
|
|
CLineService.prototype.defaultArgs ="";
|
|
|
|
CLineService.prototype.openWindowWithArgs=false;
|
|
|
|
|
|
|
|
/* factory for command line handler service (CLineService) */
|
|
|
|
CLineFactory = new Object();
|
|
|
|
|
2000-08-11 00:12:08 +04:00
|
|
|
CLineFactory.createInstance =
|
2000-07-07 18:44:26 +04:00
|
|
|
function (outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
if (!iid.equals(nsICmdLineHandler) && !iid.equals(nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
return new CLineService();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* x-application-telnet content handler */
|
|
|
|
function TelnetContentHandler ()
|
|
|
|
{}
|
|
|
|
|
|
|
|
TelnetContentHandler.prototype.queryInterface =
|
|
|
|
function (iid) {
|
|
|
|
|
|
|
|
if (!iid.equals(nsIContentHandler))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
TelnetContentHandler.prototype.handleContent =
|
2001-02-12 06:14:23 +03:00
|
|
|
function (aContentType, aCommand, aWindowTarget, aSourceContext, aChannel)
|
2000-07-07 18:44:26 +04:00
|
|
|
{
|
|
|
|
var e;
|
|
|
|
|
|
|
|
dump ("telnetLoader.handleContent (" + aContentType + ", " +
|
|
|
|
aCommand + ", " + aWindowTarget + ", " + aSourceContext + ", " +
|
|
|
|
aChannel.URI.spec + ")\n");
|
|
|
|
|
|
|
|
var xmltermChromeURL = "chrome://xmlterm/content/xmlterm.xul?"+aChannel.URI.spec;
|
2000-11-28 00:38:14 +03:00
|
|
|
//dump("telnetLoader:xmltermChromeURL = " + xmltermChromeURL + "\n");
|
2000-07-07 18:44:26 +04:00
|
|
|
|
|
|
|
var windowManager =
|
2000-09-14 03:57:52 +04:00
|
|
|
Components.classes[MEDIATOR_CONTRACTID].getService(nsIWindowMediator);
|
2000-07-07 18:44:26 +04:00
|
|
|
|
|
|
|
var w = windowManager.getMostRecentWindow("terminal:xmlterm");
|
|
|
|
|
|
|
|
// Commented out because unlike chatzilla, xmlterm is not really a service
|
|
|
|
// if (w)
|
|
|
|
// {
|
|
|
|
// // Shift focus to XMLterm window
|
|
|
|
// w.focus();
|
|
|
|
// w.gotoTelnetURL(aChannel.URI.spec);
|
|
|
|
// } else
|
|
|
|
|
|
|
|
// Create new XMLterm window
|
2000-09-14 03:57:52 +04:00
|
|
|
var ass = Components.classes[ASS_CONTRACTID].getService(nsIAppShellService);
|
2000-07-07 18:44:26 +04:00
|
|
|
var w = ass.getHiddenDOMWindow();
|
|
|
|
w.open(xmltermChromeURL, "_blank", "chrome,menubar,toolbar,resizable");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* content handler factory object (TelnetContentHandler) */
|
|
|
|
TelnetContentHandlerFactory = new Object();
|
|
|
|
|
2000-08-11 00:12:08 +04:00
|
|
|
TelnetContentHandlerFactory.createInstance =
|
2000-07-07 18:44:26 +04:00
|
|
|
function (outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
if (!iid.equals(nsIContentHandler) && !iid.equals(nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
return new TelnetContentHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* telnet protocol handler component */
|
|
|
|
function TelnetProtocolHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TelnetProtocolHandler.prototype.scheme = "telnet";
|
2000-09-24 18:22:11 +04:00
|
|
|
TelnetProtocolHandler.prototype.defaultPort = -1;
|
2000-07-07 18:44:26 +04:00
|
|
|
|
|
|
|
TelnetProtocolHandler.prototype.newURI =
|
|
|
|
function (aSpec, aBaseURI)
|
|
|
|
{
|
|
|
|
if (aBaseURI)
|
|
|
|
{
|
|
|
|
dump ("-*- telnetHandler: aBaseURI passed to newURI, bailing.\n");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
var uri = Components.classes[SIMPLEURI_CONTRACTID].createInstance(nsIURI);
|
2000-07-07 18:44:26 +04:00
|
|
|
uri.spec = aSpec;
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2000-09-24 18:22:11 +04:00
|
|
|
// "Global" variable
|
|
|
|
var gSystemPrincipal = null;
|
|
|
|
|
2000-07-07 18:44:26 +04:00
|
|
|
TelnetProtocolHandler.prototype.newChannel =
|
|
|
|
function (aURI)
|
|
|
|
{
|
2000-09-24 18:22:11 +04:00
|
|
|
var uriSpec = aURI.spec
|
2000-11-28 00:38:14 +03:00
|
|
|
//dump("TelnetProtocolHandler.newChannel: uriSpec="+uriSpec+"\n");
|
2000-09-24 18:22:11 +04:00
|
|
|
|
|
|
|
if (uriSpec != "telnet:xmlterm")
|
|
|
|
return new BogusChannel (aURI);
|
|
|
|
|
|
|
|
// Re-direct to chrome HTML document, but with system principal
|
|
|
|
|
|
|
|
var ioServ = Components.classesByID[NS_IOSERVICE_CID_STR].getService();
|
|
|
|
ioServ = ioServ.QueryInterface(nsIIOService);
|
|
|
|
|
|
|
|
// Open temporary XUL channel
|
|
|
|
var xulURI = ioServ.newURI("chrome://xmlterm/content/xmltermDummy.xul",
|
|
|
|
null);
|
|
|
|
var temChannel = ioServ.newChannelFromURI(xulURI);
|
|
|
|
|
|
|
|
// Get owner of XUL channel
|
|
|
|
var xulOwner = temChannel.owner;
|
|
|
|
|
|
|
|
if (!gSystemPrincipal) {
|
|
|
|
if (!xulOwner) {
|
|
|
|
dump("xmlterm: Internal error; unable to obtain system principal\n");
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
gSystemPrincipal = xulOwner;
|
|
|
|
}
|
|
|
|
|
2000-11-28 00:38:14 +03:00
|
|
|
//dump("gSystemPrincipal="+gSystemPrincipal+"\n");
|
2000-09-24 18:22:11 +04:00
|
|
|
|
|
|
|
// Cancel XUL request and release channel
|
2001-02-12 06:14:23 +03:00
|
|
|
temChannel.cancel(Components.results.NS_BINDING_ABORTED);
|
|
|
|
temChannel = null;
|
2000-09-24 18:22:11 +04:00
|
|
|
|
2000-11-16 21:27:16 +03:00
|
|
|
// Get current process directory
|
|
|
|
var dscontractid = "@mozilla.org/file/directory_service;1";
|
|
|
|
var ds = Components.classes[dscontractid].getService();
|
|
|
|
|
|
|
|
var dsprops = ds.QueryInterface(Components.interfaces.nsIProperties);
|
|
|
|
var file = dsprops.get("CurProcD", Components.interfaces.nsIFile);
|
|
|
|
|
|
|
|
file.append("chrome");
|
|
|
|
file.append("xmlterm.jar");
|
|
|
|
|
2000-11-28 00:38:14 +03:00
|
|
|
//dump("file="+file.path+"\n");
|
2000-11-16 21:27:16 +03:00
|
|
|
|
|
|
|
// Contruct JAR URI spec for xmlterm.html
|
|
|
|
// Use file: rather than resource: or chrome: scheme to allow
|
|
|
|
// xmlterm to load other file URLs without failing the security check
|
|
|
|
|
|
|
|
var jarURI = "jar:file:"+file.path+"!/content/xmlterm/xmlterm.html";
|
|
|
|
|
|
|
|
var newChannel = ioServ.newChannel(jarURI, null);
|
2000-09-24 18:22:11 +04:00
|
|
|
|
|
|
|
// Make new channel owned by system principal
|
|
|
|
newChannel.owner = gSystemPrincipal;
|
|
|
|
|
|
|
|
return newChannel;
|
2000-07-07 18:44:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* protocol handler factory object (TelnetProtocolHandler) */
|
|
|
|
TelnetProtocolHandlerFactory = new Object();
|
|
|
|
|
2000-08-11 00:12:08 +04:00
|
|
|
TelnetProtocolHandlerFactory.createInstance =
|
2000-07-07 18:44:26 +04:00
|
|
|
function (outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
if (!iid.equals(nsIProtocolHandler) && !iid.equals(nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
return new TelnetProtocolHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* bogus Telnet channel used by the TelnetProtocolHandler */
|
|
|
|
function BogusChannel (aURI)
|
|
|
|
{
|
|
|
|
this.URI = aURI;
|
|
|
|
this.originalURI = aURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
BogusChannel.prototype.queryInterface =
|
|
|
|
function (iid) {
|
|
|
|
|
|
|
|
if (!iid.equals(nsIChannel) && !iid.equals(nsIRequest) &&
|
|
|
|
!iid.equals(nsISupports))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIChannel */
|
2001-02-12 06:14:23 +03:00
|
|
|
BogusChannel.prototype.transferOffset = 0;
|
|
|
|
BogusChannel.prototype.transferCount = 0;
|
2000-07-07 18:44:26 +04:00
|
|
|
BogusChannel.prototype.loadAttributes = null;
|
|
|
|
BogusChannel.prototype.contentType = "x-application-telnet";
|
|
|
|
BogusChannel.prototype.contentLength = 0;
|
|
|
|
BogusChannel.prototype.owner = null;
|
|
|
|
BogusChannel.prototype.loadGroup = null;
|
|
|
|
BogusChannel.prototype.notificationCallbacks = null;
|
|
|
|
BogusChannel.prototype.securityInfo = null;
|
2001-02-12 06:14:23 +03:00
|
|
|
BogusChannel.prototype.bufferSegmentSize = 0;
|
|
|
|
BogusChannel.prototype.bufferMaxSize = 0;
|
2000-07-07 18:44:26 +04:00
|
|
|
BogusChannel.prototype.shouldCache = false;
|
2001-02-12 06:14:23 +03:00
|
|
|
BogusChannel.prototype.pipeliningAllowed = false;
|
2000-07-07 18:44:26 +04:00
|
|
|
|
2001-02-12 06:14:23 +03:00
|
|
|
BogusChannel.prototype.openInputStream =
|
|
|
|
BogusChannel.prototype.openOutputStream =
|
|
|
|
BogusChannel.prototype.asyncWrite =
|
2000-07-07 18:44:26 +04:00
|
|
|
function ()
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
BogusChannel.prototype.asyncOpen =
|
|
|
|
function (observer, ctxt)
|
|
|
|
{
|
|
|
|
observer.onStartRequest (this, ctxt);
|
|
|
|
}
|
|
|
|
|
2001-02-12 06:14:23 +03:00
|
|
|
BogusChannel.prototype.asyncRead =
|
|
|
|
function (listener, ctxt)
|
|
|
|
{
|
|
|
|
return listener.onStartRequest (this, ctxt);
|
|
|
|
}
|
|
|
|
|
2000-07-07 18:44:26 +04:00
|
|
|
/* nsIRequest */
|
|
|
|
BogusChannel.prototype.isPending =
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BogusChannel.prototype.status = Components.results.NS_OK;
|
|
|
|
|
|
|
|
BogusChannel.prototype.cancel =
|
|
|
|
function (aStatus)
|
|
|
|
{
|
|
|
|
this.status = aStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
BogusChannel.prototype.suspend =
|
|
|
|
BogusChannel.prototype.resume =
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
var XMLtermModule = new Object();
|
|
|
|
|
|
|
|
XMLtermModule.registerSelf =
|
|
|
|
function (compMgr, fileSpec, location, type)
|
|
|
|
{
|
|
|
|
dump("*** Registering -terminal handler.\n");
|
|
|
|
compMgr.registerComponentWithType(CLINE_SERVICE_CID,
|
|
|
|
"XMLterm CommandLine Service",
|
2000-09-14 03:57:52 +04:00
|
|
|
CLINE_SERVICE_CONTRACTID, fileSpec,
|
2000-07-07 18:44:26 +04:00
|
|
|
location, true, true, type);
|
|
|
|
|
2000-09-15 03:20:49 +04:00
|
|
|
catman = Components.classes["@mozilla.org/categorymanager;1"]
|
2000-07-07 18:44:26 +04:00
|
|
|
.getService(nsICategoryManager);
|
|
|
|
catman.addCategoryEntry("command-line-argument-handlers",
|
|
|
|
"xmlterm command line handler",
|
2000-09-14 03:57:52 +04:00
|
|
|
CLINE_SERVICE_CONTRACTID, true, true);
|
2000-07-07 18:44:26 +04:00
|
|
|
|
|
|
|
dump("*** Registering x-application-telnet handler.\n");
|
|
|
|
compMgr.registerComponentWithType(TELNETCNT_HANDLER_CID,
|
|
|
|
"Telnet Content Handler",
|
2000-09-14 03:57:52 +04:00
|
|
|
TELNETCNT_HANDLER_CONTRACTID, fileSpec,
|
2000-07-07 18:44:26 +04:00
|
|
|
location, true, true, type);
|
|
|
|
|
|
|
|
dump("*** Registering telnet protocol handler.\n");
|
|
|
|
compMgr.registerComponentWithType(TELNETPROT_HANDLER_CID,
|
|
|
|
"Telnet protocol handler",
|
2000-09-14 03:57:52 +04:00
|
|
|
TELNETPROT_HANDLER_CONTRACTID, fileSpec, location,
|
2000-07-07 18:44:26 +04:00
|
|
|
true, true, type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLtermModule.unregisterSelf =
|
|
|
|
function(compMgr, fileSpec, location)
|
|
|
|
{
|
|
|
|
compMgr.unregisterComponentSpec(CLINE_SERVICE_CID, fileSpec);
|
2000-09-15 03:20:49 +04:00
|
|
|
catman = Components.classes["@mozilla.org/categorymanager;1"]
|
2000-07-07 18:44:26 +04:00
|
|
|
.getService(nsICategoryManager);
|
|
|
|
catman.deleteCategoryEntry("command-line-argument-handlers",
|
2000-09-14 03:57:52 +04:00
|
|
|
CLINE_SERVICE_CONTRACTID, true);
|
2000-07-07 18:44:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
XMLtermModule.getClassObject =
|
|
|
|
function (compMgr, cid, iid) {
|
|
|
|
if (cid.equals(CLINE_SERVICE_CID))
|
|
|
|
return CLineFactory;
|
|
|
|
|
|
|
|
if (cid.equals(TELNETCNT_HANDLER_CID))
|
|
|
|
return TelnetContentHandlerFactory;
|
|
|
|
|
|
|
|
if (cid.equals(TELNETPROT_HANDLER_CID))
|
|
|
|
return TelnetProtocolHandlerFactory;
|
|
|
|
|
|
|
|
if (!iid.equals(Components.interfaces.nsIFactory))
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLtermModule.canUnload =
|
|
|
|
function(compMgr)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entrypoint */
|
|
|
|
function NSGetModule(compMgr, fileSpec) {
|
|
|
|
return XMLtermModule;
|
|
|
|
}
|