Fix bug 247486 - can't load several calendars with different passwords on same server/realm. r=mmecca,a=philipp CLOSED TREE
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 15 Sep 2011 11:26:25 +0200
changeset 8461 2aed8aff80c98c64401c54525062c7b604875e57
parent 8456 7917468a3bc012402b9a74eb11973565170da826
child 8462 1c74bb2ef964982a80103d9ab5b03ce0e96bedb2
push id131
push usermozilla@kewis.ch
push dateThu, 15 Sep 2011 09:30:28 +0000
treeherdercomm-beta@2aed8aff80c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmmecca, philipp
bugs247486
Fix bug 247486 - can't load several calendars with different passwords on same server/realm. r=mmecca,a=philipp CLOSED TREE
calendar/base/src/calCalendarManager.js
calendar/lightning/content/lightning.js
calendar/sunbird/app/profile/sunbird.js
--- a/calendar/base/src/calCalendarManager.js
+++ b/calendar/base/src/calCalendarManager.js
@@ -186,34 +186,46 @@ calCalendarManager.prototype = {
         if (cal.isSunbird()) {
             this.loginMasterPassword();
         }
         this.mNetworkCalendarCount = 0;
         this.mReadonlyCalendarCount = 0;
         this.mCalendarCount = 0;
 
         Services.obs.addObserver(this, "http-on-modify-request", false);
-        Services.obs.addObserver(this, "http-on-examine-response", false);
+
+        // We only add the observer if the pref is set and only check for the
+        // pref on startup to avoid checking for every http request
+        if (cal.getPrefSafe("calendar.network.multirealm", false)) {
+            Services.obs.addObserver(this, "http-on-examine-response", false);
+        }
 
         aCompleteListener.onResult(null, Components.results.NS_OK);
     },
 
     shutdown: function ccm_shutdown(aCompleteListener) {
         for each (var calendar in this.mCache) {
             calendar.removeObserver(this.mCalObservers[calendar.id]);
         }
 
         this.cleanupOfflineObservers();
 
         Services.obs.removeObserver(this, "profile-after-change");
         Services.obs.removeObserver(this, "profile-before-change");
         Services.obs.removeObserver(this, "http-on-modify-request");
-        Services.obs.removeObserver(this, "http-on-examine-response");
+
         AddonManager.removeAddonListener(gCalendarManagerAddonListener);
 
+        // Remove the observer if the pref is set. This might fail when the
+        // user flips the pref, but we assume he is going to restart anyway
+        // afterwards.
+        if (cal.getPrefSafe("calendar.network.multirealm", false)) {
+            Services.obs.removeObserver(this, "http-on-examine-response");
+        }
+
         aCompleteListener.onResult(null, Components.results.NS_OK);
     },
 
 
     setupOfflineObservers: function ccm_setupOfflineObservers() {
         Services.obs.addObserver(this, "network:offline-status-changed", false);
     },
 
@@ -268,17 +280,17 @@ calCalendarManager.prototype = {
                     let channel = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
                     if (channel.notificationCallbacks) {
                         // We use the notification callbacks to get the calendar interface,
                         // which likely works for our requests since getInterface is called
                         // from the calendar provider context.
                         let authHeader = channel.getResponseHeader("WWW-Authenticate");
                         let calendar = channel.notificationCallbacks
                                               .getInterface(Components.interfaces.calICalendar);
-                        if (!calendar.getProperty("capabilities.realmrewrite.disabled")) {
+                        if (calendar && !calendar.getProperty("capabilities.realmrewrite.disabled")) {
                             // The provider may choose to explicitly disable the
                             // rewriting, for example if all calendars on a
                             // domain have the same credentials
                             authHeader = authHeader.replace(/realm="(.*)"/, 'realm="$1 (' + calendar.name + ')"');
                             channel.setResponseHeader("WWW-Authenticate", authHeader, false);
                         }
                     }
                 } catch (e if e.result == Components.results.NS_NOINTERFACE ||
--- a/calendar/lightning/content/lightning.js
+++ b/calendar/lightning/content/lightning.js
@@ -135,10 +135,14 @@ pref("calendar.categories.names", "");
 
 // Make sure mouse wheel shift and no key actions to scroll lines.
 pref("mousewheel.withnokey.action", 0);
 pref("mousewheel.withshiftkey.action", 0);
 
 // Disable use of worker threads. Restart needed.
 pref("calendar.threading.disabled", false);
 
+// Enable support for multiple realms on one server with the payoff that you
+// will get multiple password dialogs (one for each calendar)
+pref("calendar.network.multirealm", false);
+
 // Set up user agent
 #expand pref("calendar.useragent.extra", "Lightning/__LIGHTNING_VERSION__");
--- a/calendar/sunbird/app/profile/sunbird.js
+++ b/calendar/sunbird/app/profile/sunbird.js
@@ -75,16 +75,20 @@ pref("calendar.view.visiblehours", 9);
 pref("calendar.view.mousescroll", true);
 
 pref("calendar.weeks.inview", 4);
 pref("calendar.previousweeks.inview", 0);
 
 // Disable use of worker threads. Restart needed.
 pref("calendar.threading.disabled", false);
 
+// Enable support for multiple realms on one server with the payoff that you
+// will get multiple password dialogs (one for each calendar)
+pref("calendar.network.multirealm", false);
+
 // default transparency of allday items; could be switched to e.g. "OPAQUE":
 pref("calendar.allday.defaultTransparency", "TRANSPARENT");
 
 // whether "notify" is checked by default when creating new events/todos with attendees
 pref("calendar.itip.notify", true);
 
 // whether the organizer propagates replies of attendees
 pref("calendar.itip.notify-replies", false);