Bug 1786971 - consolidate timezone provider and service interfaces. r=darktrojan,lasana

Differential Revision: https://phabricator.services.mozilla.com/D155541

--HG--
rename : calendar/base/public/calITimezoneProvider.idl => calendar/base/public/calITimezoneService.idl
This commit is contained in:
Sean Burke 2022-09-08 01:04:13 +00:00
Родитель 116cf83442
Коммит d84ea84248
24 изменённых файлов: 81 добавлений и 171 удалений

Просмотреть файл

@ -17,9 +17,6 @@ function onLoad() {
window.time = args.time;
window.onAcceptCallback = args.onOk;
let tzProvider = args.calendar.getProperty("timezones.provider") || cal.timezoneService;
window.tzProvider = tzProvider;
let menulist = document.getElementById("timezone-menulist");
let tzMenuPopup = document.getElementById("timezone-menupopup");
@ -33,8 +30,8 @@ function onLoad() {
let tzids = {};
let displayNames = [];
for (let timezoneId of tzProvider.timezoneIds) {
let timezone = tzProvider.getTimezone(timezoneId);
for (let timezoneId of cal.timezoneService.timezoneIds) {
let timezone = cal.timezoneService.getTimezone(timezoneId);
if (timezone && !timezone.isFloating && !timezone.isUTC) {
let displayName = timezone.displayName;
displayNames.push(displayName);
@ -90,7 +87,7 @@ function findTimezone(timezone) {
function updateTimezone() {
let menulist = document.getElementById("timezone-menulist");
let menuitem = menulist.selectedItem;
let timezone = window.tzProvider.getTimezone(menuitem.getAttribute("value"));
let timezone = cal.timezoneService.getTimezone(menuitem.getAttribute("value"));
// convert the date/time to the currently selected timezone
// and display the result in the appropriate control.
@ -123,7 +120,7 @@ document.addEventListener("dialogaccept", () => {
let menulist = document.getElementById("timezone-menulist");
let menuitem = menulist.selectedItem;
let timezoneString = menuitem.getAttribute("value");
let timezone = window.tzProvider.getTimezone(timezoneString);
let timezone = cal.timezoneService.getTimezone(timezoneString);
let datetime = window.time.getInTimezone(timezone);
window.onAcceptCallback(datetime);
});

Просмотреть файл

@ -3357,10 +3357,9 @@ editEndTimezone.complete = function(datetime) {
function chooseRecentTimezone(event) {
let tzid = event.target.value;
let timezonePopup = document.getElementById("timezone-popup");
let tzProvider = getCurrentCalendar().getProperty("timezones.provider") || cal.timezoneService;
if (tzid != "custom") {
let zone = tzProvider.getTimezone(tzid);
let zone = cal.timezoneService.getTimezone(tzid);
let datetime = timezonePopup.dateTime.getInTimezone(zone);
timezonePopup.editTimezone.complete(datetime);
}

Просмотреть файл

@ -12,7 +12,6 @@ interface calIItemBase;
interface calIDateTime;
interface calIDuration;
interface calITimezone;
interface calITimezoneProvider;
interface calIIcalProperty;
interface nsIInputStream;
@ -222,30 +221,19 @@ interface calIIcsComponentParsingListener : nsISupports
interface calIICSService : nsISupports
{
/**
* Parses an ICS string and uses the passed tzProvider instance to
* resolve timezones not contained within the VCALENDAR.
* Parse an ICS string into components.
*
* @param serialized an ICS string
* @param tzProvider timezone provider used to resolve TZIDs
* not contained within the VCALENDAR;
* if null is passed, parsing falls back to
* using the timezone service
*/
calIIcalComponent parseICS(in AUTF8String serialized,
in calITimezoneProvider tzProvider);
calIIcalComponent parseICS(in AUTF8String serialized);
/**
* Asynchronously parse an ICS string
* Asynchronously parse an ICS string into components.
*
* @param serialized an ICS string
* @param tzProvider timezone provider used to resolve TZIDs
* not contained within the VCALENDAR;
* if null is passed, parsing falls back to
* using the timezone service
* @param listener The listener that notifies the root component
*/
void parseICSAsync(in AUTF8String serialized,
in calITimezoneProvider tzProvider,
in calIIcsComponentParsingListener listener);
calIIcalComponent createIcalComponent(in AUTF8String kind);

Просмотреть файл

@ -9,7 +9,6 @@ interface calIIcalProperty;
interface calIIcalComponent;
interface calIItemBase;
interface nsIInputStream;
interface calITimezoneProvider;
interface calIIcsParser;
/**
@ -35,15 +34,11 @@ interface calIIcsParser : nsISupports
*
* @param aICSString
* The ICS string to parse
* @param optional aTzProvider
* The timezone provider used to resolve timezones not contained in the
* parent VCALENDAR or null (falls back to timezone service)
* @param optional aAsyncParsing
* If non-null, parsing will be performed on a worker thread,
* and the passed listener is called when it's done
*/
void parseString(in AString aICSString,
[optional] in calITimezoneProvider aTzProvider,
[optional] in calIIcsParsingListener aAsyncParsing);
/**
@ -52,15 +47,11 @@ interface calIIcsParser : nsISupports
* @see parseString
* @param aICSString
* The stream to parse
* @param optional aTzProvider
* The timezone provider used to resolve timezones not contained in the
* parent VCALENDAR or null (falls back to timezone service)
* @param optional aAsyncParsing
* If non-null, parsing will be performed on a worker thread,
* and the passed listener is called when it's done
*/
void parseFromStream(in nsIInputStream aStream,
[optional] in calITimezoneProvider aTzProvider,
[optional] in calIIcsParsingListener aAsyncParsing);
/**

Просмотреть файл

@ -5,16 +5,10 @@
#include "nsISupports.idl"
interface calIIcalComponent;
interface calITimezoneProvider;
[scriptable, uuid(D79161E7-0DB9-427d-A0C3-27E0DB3B030F)]
interface calITimezone : nsISupports
{
/**
* The timezone provider this timezone belongs to, if any.
*/
readonly attribute calITimezoneProvider provider;
/**
* VTIMEZONE ical component, null if floating or UTC.
*/

Просмотреть файл

@ -1,47 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsIUTF8StringEnumerator;
interface calITimezone;
[scriptable, uuid(331a7c6d-805a-4926-940b-2d78dcd90554)]
interface calITimezoneProvider : nsISupports
{
readonly attribute nsIUTF8StringEnumerator timezoneIds;
readonly attribute nsIUTF8StringEnumerator aliasIds;
/**
* Gets a timezone definition passing a TZID.
* Returns null in case of an unknown TZID.
*
* @param tzid a TZID to be resolved
* @return a timezone object or null
*/
calITimezone getTimezone(in AUTF8String tzid);
};
/**
* This service acts as a central access point for the up to date set
* of Olson timezone definitions.
*/
[scriptable, uuid(AB1BFE6A-EE95-4038-B594-34AEEDA9911A)]
interface calITimezoneService : calITimezoneProvider
{
readonly attribute calITimezone floating;
readonly attribute calITimezone UTC;
/**
* Provides the version of the underlying timezone database.
*/
readonly attribute AString version;
/**
* Returns the default timezone from calendar.timezone.local. If no timezone
* has been set, a best guess is taken from the operating system and the
* timezone is saved into the above mentioned pref.
*/
readonly attribute calITimezone defaultTimezone;
};

Просмотреть файл

@ -0,0 +1,49 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface nsIUTF8StringEnumerator;
interface calITimezone;
/**
* Provides access to timezone definitions from the IANA Time Zone Database.
*/
[scriptable, uuid(ab1bfe6a-ee95-4038-b594-34aeeda9911a)]
interface calITimezoneService : nsISupports
{
/**
* All timezone IDs provided by the current IANA Time Zone Database.
*/
readonly attribute Array<AUTF8String> timezoneIds;
/**
* The version of the IANA Time Zone Database provided.
*/
readonly attribute AUTF8String version;
/**
* Get a timezone definition by timezone ID.
*
* @param tzid timezone ID for which to return definition
* @return a timezone object, or null if ID is not recognized
*/
calITimezone getTimezone(in AUTF8String tzid);
/**
* The definition for the "floating" timezone, in which times are relative
* to local time.
*/
readonly attribute calITimezone floating;
/**
* The timezone definition for Coordinated Universal Time.
*/
readonly attribute calITimezone UTC;
/**
* Returns the current default timezone for calendars/events.
*/
readonly attribute calITimezone defaultTimezone;
};

Просмотреть файл

@ -39,7 +39,7 @@ XPIDL_SOURCES += [
"calIStartupService.idl",
"calIStatusObserver.idl",
"calITimezone.idl",
"calITimezoneProvider.idl",
"calITimezoneService.idl",
"calITodo.idl",
"calIWeekInfoService.idl",
]

Просмотреть файл

@ -354,7 +354,7 @@ CalAlarm.prototype = {
},
set icalString(val) {
this.ensureMutable();
this.icalComponent = cal.icsService.parseICS(val, null);
this.icalComponent = cal.icsService.parseICS(val);
},
promotedProps: {

Просмотреть файл

@ -94,7 +94,7 @@ CalEvent.prototype = {
],
set icalString(value) {
this.icalComponent = cal.icsService.parseICS(value, null);
this.icalComponent = cal.icsService.parseICS(value);
},
get icalString() {

Просмотреть файл

@ -571,14 +571,12 @@ CalICSService.prototype = {
QueryInterface: ChromeUtils.generateQI(["calIICSService"]),
classID: Components.ID("{c61cb903-4408-41b3-bc22-da0b27efdfe1}"),
parseICS(serialized, tzProvider) {
// TODO ical.js doesn't support tz providers, but this is usually null
// or our timezone service anyway.
parseICS(serialized) {
let comp = ICAL.parse(serialized);
return new calIcalComponent(new ICAL.Component(comp));
},
parseICSAsync(serialized, tzProvider, listener) {
parseICSAsync(serialized, listener) {
// There are way too many error checking messages here, but I had so
// much pain with this method that I don't want it to break again.
try {

Просмотреть файл

@ -130,7 +130,7 @@ CalIcsParser.prototype = {
});
},
parseString(aICSString, aTzProvider, aAsyncParsing) {
parseString(aICSString, aAsyncParsing) {
if (aAsyncParsing) {
let self = this;
@ -139,7 +139,7 @@ CalIcsParser.prototype = {
// parser containing the processed items.
// The listener passed to parseICSAsync is a calICsComponentParsingListener
// required by the ics service, that receives the parsed root component.
cal.icsService.parseICSAsync(aICSString, aTzProvider, {
cal.icsService.parseICSAsync(aICSString, {
onParsingComplete(rc, rootComp) {
if (Components.isSuccessCode(rc)) {
self.processIcalComponent(rootComp, aAsyncParsing);
@ -151,7 +151,7 @@ CalIcsParser.prototype = {
});
} else {
try {
let icalComp = cal.icsService.parseICS(aICSString, aTzProvider);
let icalComp = cal.icsService.parseICS(aICSString);
this.processIcalComponent(icalComp);
} catch (exc) {
cal.ERROR(exc.message + " when parsing\n" + aICSString);
@ -159,7 +159,7 @@ CalIcsParser.prototype = {
}
},
parseFromStream(aStream, aTzProvider, aAsyncParsing) {
parseFromStream(aStream, aAsyncParsing) {
// Read in the string. Note that it isn't a real string at this point,
// because likely, the file is utf8. The multibyte chars show up as multiple
// 'chars' in this string. So call it an array of octets for now.
@ -167,7 +167,7 @@ CalIcsParser.prototype = {
let stringData = NetUtil.readInputStreamToString(aStream, aStream.available(), {
charset: "utf-8",
});
this.parseString(stringData, aTzProvider, aAsyncParsing);
this.parseString(stringData, aAsyncParsing);
},
getItems() {

Просмотреть файл

@ -87,7 +87,7 @@ CalItipItem.prototype = {
init(aIcalString) {
let parser = Cc["@mozilla.org/calendar/ics-parser;1"].createInstance(Ci.calIIcsParser);
parser.parseString(aIcalString, null);
parser.parseString(aIcalString);
// - User specific alarms as well as X-MOZ- properties are irrelevant w.r.t. iTIP messages,
// should not be sent out and should not be relevant for incoming messages

Просмотреть файл

@ -14,26 +14,6 @@ const { CalTimezone } = ChromeUtils.import("resource:///modules/CalTimezone.jsm"
const TIMEZONE_CHANGED_TOPIC = "default-timezone-changed";
function calStringEnumerator(stringArray) {
this.mIndex = 0;
this.mStringArray = stringArray;
}
calStringEnumerator.prototype = {
// nsIUTF8StringEnumerator:
[Symbol.iterator]() {
return this.mStringArray.values();
},
hasMore() {
return this.mIndex < this.mStringArray.length;
},
getNext() {
if (!this.hasMore()) {
throw Components.Exception("", Cr.NS_ERROR_UNEXPECTED);
}
return this.mStringArray[this.mIndex++];
},
};
function CalTimezoneService() {
this.wrappedJSObject = this;
@ -42,22 +22,14 @@ function CalTimezoneService() {
ICAL.TimezoneService = this.wrappedJSObject;
}
var calTimezoneServiceClassID = Components.ID("{e736f2bd-7640-4715-ab35-887dc866c587}");
var calTimezoneServiceInterfaces = [
Ci.calITimezoneService,
Ci.calITimezoneProvider,
Ci.calIStartupService,
];
var calTimezoneServiceInterfaces = [Ci.calITimezoneService, Ci.calIStartupService];
CalTimezoneService.prototype = {
mDefaultTimezone: null,
mVersion: null,
mZones: null,
classID: calTimezoneServiceClassID,
QueryInterface: cal.generateQI([
"calITimezoneService",
"calITimezoneProvider",
"calIStartupService",
]),
QueryInterface: cal.generateQI(["calITimezoneService", "calIStartupService"]),
classInfo: cal.generateCI({
classID: calTimezoneServiceClassID,
contractID: "@mozilla.org/calendar/timezone-service;1",
@ -179,7 +151,6 @@ CalTimezoneService.prototype = {
return this.mZones.get("floating").zone;
},
// calITimezoneProvider:
getTimezone(tzid) {
if (!tzid) {
cal.ERROR("Unknown timezone requested\n" + cal.STACK(10));
@ -229,17 +200,7 @@ CalTimezoneService.prototype = {
zones.push(k);
}
}
return new calStringEnumerator(zones);
},
get aliasIds() {
let zones = [];
for (let [key, value] of this.mZones.entries()) {
if (value.aliasTo && key != "UTC" && key != "floating") {
zones.push(key);
}
}
return new calStringEnumerator(zones);
return zones;
},
get version() {

Просмотреть файл

@ -135,7 +135,7 @@ CalTodo.prototype = {
],
set icalString(value) {
this.icalComponent = cal.icsService.parseICS(value, null);
this.icalComponent = cal.icsService.parseICS(value);
},
get icalString() {

Просмотреть файл

@ -30,7 +30,7 @@ CalIcsImporter.prototype = {
importFromStream(aStream) {
let parser = Cc["@mozilla.org/calendar/ics-parser;1"].createInstance(Ci.calIIcsParser);
parser.parseFromStream(aStream, null);
parser.parseFromStream(aStream);
return parser.getItems();
},
};

Просмотреть файл

@ -1128,7 +1128,7 @@ class FreeBusyResponse extends CalDavSimpleResponse {
if (caldata) {
let component;
try {
component = cal.icsService.parseICS(caldata, null);
component = cal.icsService.parseICS(caldata);
} catch (e) {
cal.LOG("CalDAV: Could not parse freebusy data: " + e);
continue;

Просмотреть файл

@ -274,7 +274,7 @@ CalICSCalendar.prototype = {
self.unlock();
},
};
parser.parseString(str, null, listener);
parser.parseString(str, listener);
},
writeICS() {

Просмотреть файл

@ -145,10 +145,7 @@ function getTimezone(aTimezone) {
if (!timezone) {
try {
// cannot cope without parent VCALENDAR:
let comp = cal.icsService.parseICS(
"BEGIN:VCALENDAR\n" + aTimezone + "\nEND:VCALENDAR",
null
);
let comp = cal.icsService.parseICS("BEGIN:VCALENDAR\n" + aTimezone + "\nEND:VCALENDAR");
timezone = new calStorageTimezone(comp.getFirstSubcomponent("VTIMEZONE"));
gForeignTimezonesCache[aTimezone] = timezone;
} catch (e) {

Просмотреть файл

@ -31,7 +31,7 @@ function test_freebusy() {
"\n" +
"END:VFREEBUSY\n" +
"END:VCALENDAR\n";
let fbComp = icsService.parseICS(data, null).getFirstSubcomponent("VFREEBUSY");
let fbComp = icsService.parseICS(data).getFirstSubcomponent("VFREEBUSY");
equal(fbComp.getFirstProperty("FREEBUSY").value, fbVal1);
equal(fbComp.getNextProperty("FREEBUSY").value, fbVal2);
equal(fbComp.getNextProperty("FREEBUSY").value, fbVal3);

Просмотреть файл

@ -135,7 +135,7 @@ function test_roundtrip() {
// foreach loop iterations.
do_test_pending();
let thisdata = data;
cal.icsService.parseICSAsync(data.ics, null, {
cal.icsService.parseICSAsync(data.ics, {
onParsingComplete(rc, rootComp) {
try {
ok(Components.isSuccessCode(rc));

Просмотреть файл

@ -45,7 +45,7 @@ function test_failures() {
let parser = Cc["@mozilla.org/calendar/ics-parser;1"].createInstance(Ci.calIIcsParser);
do_test_pending();
parser.parseString("BOGUS", null, {
parser.parseString("BOGUS", {
onParsingComplete(rc, opparser) {
dump("Note: The previous error message is expected ^^\n");
equal(rc, Cr.NS_ERROR_FAILURE);
@ -116,7 +116,7 @@ function test_async() {
].join("\r\n");
do_test_pending();
parser.parseString(str, null, {
parser.parseString(str, {
onParsingComplete(rc, opparser) {
let items = parser.getItems();
equal(items.length, 2);

Просмотреть файл

@ -258,7 +258,7 @@ function test_iterator() {
// Property iterator with multiple values
// eslint-disable-next-line no-useless-concat
comp = cal.icsService.parseICS("BEGIN:VEVENT\r\n" + "CATEGORIES:a,b,c\r\n" + "END:VEVENT", null);
comp = cal.icsService.parseICS("BEGIN:VEVENT\r\n" + "CATEGORIES:a,b,c\r\n" + "END:VEVENT");
let propValues = ["a", "b", "c"];
for (
let prop = comp.getFirstProperty("CATEGORIES");

Просмотреть файл

@ -45,23 +45,6 @@ add_task(async function zone_test() {
ok(foundZone, "There is at least one timezone");
});
// check whether all tz aliases resolve to a tz definition
add_task(async function alias_test() {
function resolveAlias(aAliasId) {
let timezone = cal.timezoneService.getTimezone(aAliasId);
let tzid = timezone && timezone.tzid ? timezone.tzid : "";
notEqual(tzid, "", "Alias resolution " + aAliasId + " -> " + tzid);
}
let foundAlias = false;
for (let aliasId of cal.timezoneService.aliasIds) {
foundAlias = true;
resolveAlias(aliasId);
}
ok(foundAlias, "There is at least one alias");
});
// Check completeness to avoid unintended removing of zones/aliases when updating zones.json
// removed zones should at least remain as alias to not break UI like in bug 1210723.
// previous.json is generated automatically by executing update-zones.py script