Bug 1630943 - Fix multiple caldav calendars on same host with different usernames. r=darktrojan
authorPaul Morris <paul@thunderbird.net>
Tue, 19 May 2020 12:57:06 +0300
changeset 39180 c827ec349a361a8f647744e23275fc414addf30d
parent 39179 601e259021fbcec11fc69111f0ca04ac7b851c27
child 39181 bc7e17995e196b439e49de01b3774726b912b960
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersdarktrojan
bugs1630943
Bug 1630943 - Fix multiple caldav calendars on same host with different usernames. r=darktrojan
calendar/base/modules/utils/calProviderUtils.jsm
calendar/providers/caldav/modules/CalDavRequest.jsm
--- a/calendar/base/modules/utils/calProviderUtils.jsm
+++ b/calendar/base/modules/utils/calProviderUtils.jsm
@@ -15,43 +15,43 @@ ChromeUtils.defineModuleGetter(this, "ca
 // including calUtils.jsm under the cal.provider namespace.
 
 const EXPORTED_SYMBOLS = ["calprovider"]; /* exported calprovider */
 
 var calprovider = {
   /**
    * Prepare HTTP channel with standard request headers and upload data/content-type if needed.
    *
-   * @param {nsIURI} aUri                                     Channel Uri, will only be used for a
-   *                                                            new channel.
-   * @param {nsIInputStream|String} aUploadData               Data to be uploaded, if any. This
-   *                                                            may be a nsIInputStream or string
-   *                                                            data. In the latter case the
-   *                                                            string will be converted to an
-   *                                                            input stream.
-   * @param {String} aContentType                             Value for Content-Type header, if any
-   * @param {nsIInterfaceRequestor} aNotificationCallbacks    Calendar using channel
-   * @param {?nsIChannel} aExisting                           An existing channel to modify (optional)
-   * @return {nsIChannel}                                     The prepared channel
+   * @param {nsIURI} aUri                             The channel URI, only used for a new channel.
+   * @param {nsIInputStream|String} aUploadData       Data to be uploaded, if any. If a string,
+   *                                                    it will be converted to an nsIInputStream.
+   * @param {String} aContentType                     Value for Content-Type header, if any.
+   * @param {nsIInterfaceRequestor} aNotificationCallbacks    Typically a CalDavRequestBase which
+   *                                                            implements nsIInterfaceRequestor
+   *                                                            and nsIChannelEventSink, and
+   *                                                            provides access to the calICalendar
+   *                                                            associated with the channel.
+   * @param {nsIChannel} [aExisting]                  An existing channel to modify (optional).
+   * @return {nsIChannel}                             The prepared channel.
    */
   prepHttpChannel(aUri, aUploadData, aContentType, aNotificationCallbacks, aExisting = null) {
     let originAttributes = {};
 
     // The current nsIHttpChannel implementation separates connections only
     // by hosts, which causes issues with cookies and password caching for
     // two or more simultaneous connections to the same host and different
     // authenticated users. This can be solved by providing the additional
     // userContextId, which also separates connections (a.k.a. containers).
     // Connections for userA @ server1 and userA @ server2 can exist in the
     // same container, as nsIHttpChannel will separate them. Connections
     // for userA @ server1 and userB @ server1 however must be placed into
     // different containers. It is therefore sufficient to add individual
     // userContextIds per username.
 
-    let calendar = cal.wrapInstance(aNotificationCallbacks, Ci.calICalendar);
+    let calendar = aNotificationCallbacks.getInterface(Ci.calICalendar);
     if (calendar && calendar.getProperty("capabilities.username.supported") === true) {
       originAttributes.userContextId = cal.auth.containerMap.getUserContextIdForUsername(
         calendar.getProperty("username")
       );
     }
 
     // We cannot use a system principal here since the connection setup will fail if
     // same-site cookie protection is enabled in TB and server-side.
--- a/calendar/providers/caldav/modules/CalDavRequest.jsm
+++ b/calendar/providers/caldav/modules/CalDavRequest.jsm
@@ -27,16 +27,19 @@ const EXPORTED_SYMBOLS = [
 ];
 
 const XML_HEADER = '<?xml version="1.0" encoding="UTF-8"?>\n';
 const MIME_TEXT_CALENDAR = "text/calendar; charset=utf-8";
 const MIME_TEXT_XML = "text/xml; charset=utf-8";
 
 /**
  * Base class for a caldav request.
+ *
+ * @implements {nsIChannelEventSink}
+ * @implements {nsIInterfaceRequestor}
  */
 class CalDavRequestBase {
   QueryInterface(aIID) {
     return cal.generateClassQI(this, aIID, [Ci.nsIChannelEventSink, Ci.nsIInterfaceRequestor]);
   }
 
   /**
    * Creates a new base response, this should mainly be done using the subclass constructor