2002-09-03 23:03:55 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file contains the following chatzilla related components:
|
2002-10-25 23:28:14 +04:00
|
|
|
* 1. Command line handler service, for responding to the -webcal command line
|
2002-09-03 23:03:55 +04:00
|
|
|
* option. (CLineHandler)
|
2002-10-25 23:28:14 +04:00
|
|
|
* 2. Content handler for responding to content of type text/calendar
|
|
|
|
* (ICALContentHandler)
|
|
|
|
* 3. Protocol handler for supplying a channel to the browser when an webcal://
|
|
|
|
* link is clicked. (ICALProtocolHandler)
|
2002-09-03 23:03:55 +04:00
|
|
|
* 4. A (nearly empty) imeplementation of nsIChannel for telling the browser
|
2002-10-25 23:28:14 +04:00
|
|
|
* that webcal:// links have the content type text/calendar (BogusChannel)
|
2002-09-03 23:03:55 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* components defined in this file */
|
|
|
|
const CLINE_SERVICE_CONTRACTID =
|
2002-09-10 20:59:53 +04:00
|
|
|
"@mozilla.org/commandlinehandler/general-startup;1?type=webcal";
|
2002-09-03 23:03:55 +04:00
|
|
|
const CLINE_SERVICE_CID =
|
|
|
|
Components.ID("{65ef4b0b-d116-4b93-bf8a-84525992bf27}");
|
2002-10-25 23:28:14 +04:00
|
|
|
const ICALCNT_HANDLER_CONTRACTID =
|
2002-09-11 21:57:59 +04:00
|
|
|
"@mozilla.org/uriloader/content-handler;1?type=text/calendar";
|
2002-10-25 23:28:14 +04:00
|
|
|
const ICALCNT_HANDLER_CID =
|
2002-09-03 23:03:55 +04:00
|
|
|
Components.ID("{9ebf4c8a-7770-40a6-aeed-e1738129535a}");
|
2002-10-25 23:28:14 +04:00
|
|
|
const ICALPROT_HANDLER_CONTRACTID =
|
2002-09-10 20:59:53 +04:00
|
|
|
"@mozilla.org/network/protocol;1?name=webcal";
|
2002-10-25 23:28:14 +04:00
|
|
|
const ICALPROT_HANDLER_CID =
|
2002-09-03 23:03:55 +04:00
|
|
|
Components.ID("{d320ba05-88cf-44a6-b718-87a72ef05918}");
|
|
|
|
|
|
|
|
/* components used in this file */
|
|
|
|
const MEDIATOR_CONTRACTID =
|
|
|
|
"@mozilla.org/appshell/window-mediator;1";
|
|
|
|
const STANDARDURL_CONTRACTID =
|
|
|
|
"@mozilla.org/network/standard-url;1";
|
|
|
|
const ASS_CONTRACTID =
|
|
|
|
"@mozilla.org/appshell/appShellService;1";
|
|
|
|
|
|
|
|
/* interafces used in this file */
|
|
|
|
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 nsIStandardURL = Components.interfaces.nsIStandardURL;
|
|
|
|
const nsIChannel = Components.interfaces.nsIChannel;
|
|
|
|
const nsIRequest = Components.interfaces.nsIRequest;
|
|
|
|
const nsIAppShellService = Components.interfaces.nsIAppShellService;
|
|
|
|
const nsISupports = Components.interfaces.nsISupports;
|
|
|
|
|
|
|
|
/* Command Line handler service */
|
|
|
|
function CLineService()
|
|
|
|
{}
|
|
|
|
|
2002-09-10 20:59:53 +04:00
|
|
|
CLineService.prototype.commandLineArgument = "-webcal";
|
|
|
|
CLineService.prototype.prefNameForStartup = "general.startup.webal";
|
2002-09-03 23:03:55 +04:00
|
|
|
CLineService.prototype.chromeUrlForTask="chrome://calendar/content";
|
|
|
|
CLineService.prototype.helpText = "Start with an Calendar client";
|
|
|
|
CLineService.prototype.handlesArgs=false;
|
|
|
|
CLineService.prototype.defaultArgs ="";
|
|
|
|
CLineService.prototype.openWindowWithArgs=false;
|
|
|
|
|
|
|
|
/* factory for command line handler service (CLineService) */
|
|
|
|
var CLineFactory = new Object();
|
|
|
|
|
|
|
|
CLineFactory.createInstance =
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
/* text/calendar content handler */
|
|
|
|
function ICALContentHandler ()
|
2002-09-03 23:03:55 +04:00
|
|
|
{}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALContentHandler.prototype.QueryInterface =
|
2002-09-03 23:03:55 +04:00
|
|
|
function (iid) {
|
|
|
|
|
|
|
|
if (!iid.equals(nsIContentHandler))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALContentHandler.prototype.handleContent =
|
2002-09-03 23:03:55 +04:00
|
|
|
function (aContentType, aCommand, aWindowTarget, aRequest)
|
|
|
|
{
|
|
|
|
var e;
|
|
|
|
var channel = aRequest.QueryInterface(nsIChannel);
|
|
|
|
|
|
|
|
/*
|
2002-10-25 23:28:14 +04:00
|
|
|
dump ("ICALContentHandler.handleContent (" + aContentType + ", " +
|
2002-09-03 23:03:55 +04:00
|
|
|
aCommand + ", " + aWindowTarget + ", " + channel.URI.spec + ")\n");
|
|
|
|
*/
|
|
|
|
|
|
|
|
var windowManager =
|
|
|
|
Components.classes[MEDIATOR_CONTRACTID].getService(nsIWindowMediator);
|
|
|
|
|
|
|
|
var w = windowManager.getMostRecentWindow("calendarMainWindow");
|
|
|
|
|
|
|
|
if (w)
|
|
|
|
{
|
|
|
|
w.focus();
|
2002-09-11 21:57:59 +04:00
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
w.gCalendarWindow.calendarManager.checkCalendarURL( channel );
|
2002-09-03 23:03:55 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var ass =
|
|
|
|
Components.classes[ASS_CONTRACTID].getService(nsIAppShellService);
|
|
|
|
w = ass.hiddenDOMWindow;
|
|
|
|
|
|
|
|
var args = new Object ();
|
2002-11-01 20:59:57 +03:00
|
|
|
args.channel = channel;
|
2002-09-12 23:24:29 +04:00
|
|
|
w.openDialog("chrome://calendar/content/calendar.xul", "calendar", "chrome,menubar,resizable,scrollbars,status,toolbar,dialog=no", args);
|
2002-09-03 23:03:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
/* content handler factory object (ICALContentHandler) */
|
|
|
|
var ICALContentHandlerFactory = new Object();
|
2002-09-03 23:03:55 +04:00
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALContentHandlerFactory.createInstance =
|
2002-09-03 23:03:55 +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;
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
return new ICALContentHandler();
|
2002-09-03 23:03:55 +04:00
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
/* webcal protocol handler component */
|
|
|
|
function ICALProtocolHandler()
|
2002-09-03 23:03:55 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALProtocolHandler.prototype.scheme = "webcal";
|
|
|
|
ICALProtocolHandler.prototype.defaultPort = 8080;
|
|
|
|
ICALProtocolHandler.prototype.protocolFlags =
|
2002-09-03 23:03:55 +04:00
|
|
|
nsIProtocolHandler.URI_NORELATIVE |
|
|
|
|
nsIProtocolHandler.ALLOWS_PROXY;
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALProtocolHandler.prototype.allowPort =
|
2002-09-03 23:03:55 +04:00
|
|
|
function (aPort, aScheme)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALProtocolHandler.prototype.newURI =
|
2002-09-03 23:03:55 +04:00
|
|
|
function (aSpec, aCharset, aBaseURI)
|
|
|
|
{
|
|
|
|
var url = Components.classes[STANDARDURL_CONTRACTID].
|
|
|
|
createInstance(nsIStandardURL);
|
2002-09-10 20:59:53 +04:00
|
|
|
url.init(nsIStandardURL.URLTYPE_STANDARD, 8080, aSpec, aCharset, aBaseURI);
|
2002-09-03 23:03:55 +04:00
|
|
|
|
|
|
|
return url.QueryInterface(nsIURI);
|
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALProtocolHandler.prototype.newChannel =
|
2002-09-10 20:59:53 +04:00
|
|
|
function (aURI)
|
|
|
|
{
|
|
|
|
return new BogusChannel (aURI);
|
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
/* protocol handler factory object (ICALProtocolHandler) */
|
|
|
|
var ICALProtocolHandlerFactory = new Object();
|
2002-09-03 23:03:55 +04:00
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALProtocolHandlerFactory.createInstance =
|
2002-09-03 23:03:55 +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;
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
return new ICALProtocolHandler();
|
2002-09-10 20:59:53 +04:00
|
|
|
}
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
/* bogus webcal channel used by the ICALProtocolHandler */
|
2002-09-10 20:59:53 +04:00
|
|
|
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 */
|
|
|
|
BogusChannel.prototype.loadAttributes = null;
|
2002-09-11 21:57:59 +04:00
|
|
|
BogusChannel.prototype.contentType = "text/calendar";
|
2002-09-10 20:59:53 +04:00
|
|
|
BogusChannel.prototype.contentLength = 0;
|
|
|
|
BogusChannel.prototype.owner = null;
|
|
|
|
BogusChannel.prototype.loadGroup = null;
|
|
|
|
BogusChannel.prototype.notificationCallbacks = null;
|
|
|
|
BogusChannel.prototype.securityInfo = null;
|
|
|
|
|
|
|
|
BogusChannel.prototype.open =
|
|
|
|
BogusChannel.prototype.asyncOpen =
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
BogusChannel.prototype.asyncOpen =
|
|
|
|
function (observer, ctxt)
|
|
|
|
{
|
|
|
|
observer.onStartRequest (this, ctxt);
|
|
|
|
}
|
|
|
|
|
|
|
|
BogusChannel.prototype.asyncRead =
|
|
|
|
function (listener, ctxt)
|
|
|
|
{
|
|
|
|
return listener.onStartRequest (this, ctxt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIRequest */
|
|
|
|
BogusChannel.prototype.isPending =
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
return true;
|
2002-09-03 23:03:55 +04:00
|
|
|
}
|
|
|
|
|
2002-09-10 20:59:53 +04:00
|
|
|
BogusChannel.prototype.status = Components.results.NS_OK;
|
|
|
|
|
|
|
|
BogusChannel.prototype.cancel =
|
|
|
|
function (aStatus)
|
|
|
|
{
|
|
|
|
this.status = aStatus;
|
|
|
|
}
|
2002-09-03 23:03:55 +04:00
|
|
|
|
2002-09-10 20:59:53 +04:00
|
|
|
BogusChannel.prototype.suspend =
|
|
|
|
BogusChannel.prototype.resume =
|
|
|
|
function ()
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ChatzillaModule = new Object();
|
|
|
|
|
|
|
|
ChatzillaModule.registerSelf =
|
2002-09-03 23:03:55 +04:00
|
|
|
function (compMgr, fileSpec, location, type)
|
|
|
|
{
|
2002-09-10 20:59:53 +04:00
|
|
|
dump("*** Registering -webcal handler.\n");
|
2002-09-03 23:03:55 +04:00
|
|
|
|
|
|
|
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
|
|
|
|
compMgr.registerFactoryLocation(CLINE_SERVICE_CID,
|
|
|
|
"Calendar CommandLine Service",
|
|
|
|
CLINE_SERVICE_CONTRACTID,
|
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
|
|
|
|
|
|
|
catman = Components.classes["@mozilla.org/categorymanager;1"]
|
|
|
|
.getService(nsICategoryManager);
|
|
|
|
catman.addCategoryEntry("command-line-argument-handlers",
|
|
|
|
"calendar command line handler",
|
|
|
|
CLINE_SERVICE_CONTRACTID, true, true);
|
|
|
|
|
2002-09-11 21:57:59 +04:00
|
|
|
dump("*** Registering text/calendar handler.\n");
|
2002-10-25 23:28:14 +04:00
|
|
|
compMgr.registerFactoryLocation(ICALCNT_HANDLER_CID,
|
2002-09-10 20:59:53 +04:00
|
|
|
"Webcal Content Handler",
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALCNT_HANDLER_CONTRACTID,
|
2002-09-10 20:59:53 +04:00
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
|
|
|
|
|
|
|
dump("*** Registering webcal protocol handler.\n");
|
2002-10-25 23:28:14 +04:00
|
|
|
compMgr.registerFactoryLocation(ICALPROT_HANDLER_CID,
|
2002-09-10 20:59:53 +04:00
|
|
|
"Webcal protocol handler",
|
2002-10-25 23:28:14 +04:00
|
|
|
ICALPROT_HANDLER_CONTRACTID,
|
2002-09-03 23:03:55 +04:00
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
|
|
|
}
|
|
|
|
|
2002-09-10 20:59:53 +04:00
|
|
|
ChatzillaModule.unregisterSelf =
|
2002-09-03 23:03:55 +04:00
|
|
|
function(compMgr, fileSpec, location)
|
|
|
|
{
|
|
|
|
|
|
|
|
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
|
|
|
|
compMgr.unregisterFactoryLocation(CLINE_SERVICE_CID,
|
|
|
|
fileSpec);
|
|
|
|
catman = Components.classes["@mozilla.org/categorymanager;1"]
|
|
|
|
.getService(nsICategoryManager);
|
|
|
|
catman.deleteCategoryEntry("command-line-argument-handlers",
|
|
|
|
CLINE_SERVICE_CONTRACTID, true);
|
|
|
|
}
|
|
|
|
|
2002-09-10 20:59:53 +04:00
|
|
|
ChatzillaModule.getClassObject =
|
2002-09-03 23:03:55 +04:00
|
|
|
function (compMgr, cid, iid) {
|
|
|
|
if (cid.equals(CLINE_SERVICE_CID))
|
|
|
|
return CLineFactory;
|
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
if (cid.equals(ICALCNT_HANDLER_CID))
|
|
|
|
return ICALContentHandlerFactory;
|
2002-09-03 23:03:55 +04:00
|
|
|
|
2002-10-25 23:28:14 +04:00
|
|
|
if (cid.equals(ICALPROT_HANDLER_CID))
|
|
|
|
return ICALProtocolHandlerFactory;
|
2002-09-03 23:03:55 +04:00
|
|
|
|
|
|
|
if (!iid.equals(Components.interfaces.nsIFactory))
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-09-10 20:59:53 +04:00
|
|
|
ChatzillaModule.canUnload =
|
2002-09-03 23:03:55 +04:00
|
|
|
function(compMgr)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* entrypoint */
|
|
|
|
function NSGetModule(compMgr, fileSpec) {
|
2002-09-10 20:59:53 +04:00
|
|
|
return ChatzillaModule;
|
2002-09-03 23:03:55 +04:00
|
|
|
}
|