mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 19:33:18 +00:00
Make subscribing to a webcal calendar from a link in a browser work. Bug 295896, r=pavlov
This commit is contained in:
parent
b1f8fe7021
commit
52a70e374a
@ -110,7 +110,7 @@ calICSCalendar.prototype = {
|
||||
mUri: null,
|
||||
get uri() { return this.mUri },
|
||||
set uri(aUri) {
|
||||
this.mMemoryCalendar.uri = aUri;
|
||||
this.mMemoryCalendar.uri = this.mUri;
|
||||
// Lock other changes to the item list.
|
||||
this.locked = true;
|
||||
// set to prevent writing after loading, without any changes
|
||||
@ -121,7 +121,7 @@ calICSCalendar.prototype = {
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
|
||||
var channel = ioService.newChannelFromURI(this.mUri);
|
||||
var channel = ioService.newChannelFromURI(fixupUri(this.mUri));
|
||||
channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
|
||||
channel.notificationCallbacks = this;
|
||||
|
||||
@ -229,7 +229,7 @@ calICSCalendar.prototype = {
|
||||
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var channel = ioService.newChannelFromURI(savedthis.mUri);
|
||||
var channel = ioService.newChannelFromURI(fixupUri(savedthis.mUri));
|
||||
channel.notificationCallbacks = savedthis;
|
||||
var uploadChannel = channel.QueryInterface(Components.interfaces.nsIUploadChannel);
|
||||
var postStream = Components.classes["@mozilla.org/io/string-input-stream;1"]
|
||||
@ -372,6 +372,15 @@ calICSCalendar.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function fixupUri(aUri) {
|
||||
var uri = aUri;
|
||||
if (uri.scheme == 'webcal')
|
||||
uri.scheme = 'http';
|
||||
if (uri.scheme == 'webcals')
|
||||
uri.scheme = 'https';
|
||||
return uri;
|
||||
}
|
||||
|
||||
function calICSObserver(aCalendar) {
|
||||
this.mCalendar = aCalendar;
|
||||
this.mObservers = new Array();
|
||||
|
@ -161,51 +161,43 @@ function (iid) {
|
||||
}
|
||||
|
||||
ICALContentHandler.prototype.handleContent =
|
||||
function (aContentType, param2, param3, param4)
|
||||
function(aContentType, aWindowTarget, aRequest)
|
||||
{
|
||||
|
||||
var aWindowTarget, aRequest;
|
||||
if (param4 === undefined)
|
||||
{// Moz1.8+ uses 3 params: (aContentType, aWindowTarget, aRequest)
|
||||
aWindowTarget = param2;
|
||||
aRequest = param3;
|
||||
}
|
||||
else
|
||||
{// Moz1.7- uses 4 params: (aContentType, aCommand, aWindowTarget, aRequest)
|
||||
aWindowTarget = param3;
|
||||
aRequest = param4;
|
||||
}
|
||||
|
||||
var e;
|
||||
var channel = aRequest.QueryInterface(nsIChannel);
|
||||
|
||||
/*
|
||||
dump ("ICALContentHandler.handleContent (" + aContentType + ", " +
|
||||
aWindowTarget + ", " + channel.URI.spec + ")\n");
|
||||
*/
|
||||
// Cancel the request ...
|
||||
var uri = channel.URI;
|
||||
const NS_BINDING_ABORTED = 0x804b0002 // from nsNetError.h
|
||||
aRequest.cancel(NS_BINDING_ABORTED);
|
||||
|
||||
var windowManager =
|
||||
Components.classes[MEDIATOR_CONTRACTID].getService(nsIWindowMediator);
|
||||
// ... Subscribe to the uri ...
|
||||
var calendarManager = Components.classes["@mozilla.org/calendar/manager;1"]
|
||||
.getService(Components.interfaces.calICalendarManager);
|
||||
|
||||
var newCalendar = calendarManager.createCalendar('ics', uri);
|
||||
calendarManager.registerCalendar(newCalendar);
|
||||
|
||||
// XXX Come up with a better name, like the filename or X-WR-CALNAME
|
||||
// XXX Also, make up a color
|
||||
newCalendar.name = "temp";
|
||||
|
||||
// ... and open or focus a calendar window.
|
||||
var windowManager = Components.classes[MEDIATOR_CONTRACTID]
|
||||
.getService(nsIWindowMediator);
|
||||
|
||||
var w = windowManager.getMostRecentWindow("calendarMainWindow");
|
||||
|
||||
if (w)
|
||||
{
|
||||
if (w) {
|
||||
w.focus();
|
||||
|
||||
w.gCalendarWindow.calendarManager.checkCalendarURL( channel );
|
||||
}
|
||||
else
|
||||
{
|
||||
var ass =
|
||||
Components.classes[ASS_CONTRACTID].getService(nsIAppShellService);
|
||||
} else {
|
||||
var ass = Components.classes[ASS_CONTRACTID]
|
||||
.getService(nsIAppShellService);
|
||||
w = ass.hiddenDOMWindow;
|
||||
|
||||
var args = new Object ();
|
||||
args.channel = channel;
|
||||
w.openDialog("chrome://calendar/content/calendar.xul", "calendar", "chrome,menubar,resizable,scrollbars,status,toolbar,dialog=no", args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* content handler factory object (ICALContentHandler) */
|
||||
|
Loading…
Reference in New Issue
Block a user