Bug 821595 - No option to remember password for CalDAV calendar. r+a=philipp
authorMatthew Mecca <matthew.mecca@gmail.com>
Fri, 15 Feb 2013 21:48:26 -0500
changeset 14654 03bac50b08eb17bd66913258ee64e92462ab503d
parent 14653 ec4828fcca96eb6be1fbacd1024be78628f5fd53
child 14655 e5bc1e8200212e6df7cf1a4b19bf29576ad7476e
push id845
push userbugzilla@standard8.plus.com
push dateTue, 19 Feb 2013 18:11:16 +0000
treeherdercomm-beta@ecc3ce2d7daa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs821595
Bug 821595 - No option to remember password for CalDAV calendar. r+a=philipp
calendar/base/modules/calAuthUtils.jsm
calendar/base/modules/calProviderUtils.jsm
--- a/calendar/base/modules/calAuthUtils.jsm
+++ b/calendar/base/modules/calAuthUtils.jsm
@@ -9,17 +9,18 @@ Components.utils.import("resource://gre/
  * Authentication helper code
  */
 
 EXPORTED_SYMBOLS = ["cal"]; // even though it's defined in calUtils.jsm, import needs this
 cal.auth = {
     /**
      * Auth prompt implementation - Uses password manager if at all possible.
      */
-    Prompt: function calPrompt() {
+    Prompt: function calPrompt(aProvider) {
+        this.mProvider = aProvider;
         this.mReturnedLogins = {};
     },
 
     /**
      * Tries to get the username/password combination of a specific calendar name
      * from the password manager or asks the user.
      *
      * @param   in aTitle           The dialog title.
@@ -163,16 +164,18 @@ cal.auth = {
  * nsIAuthPrompt2 and friends.
  *
  * This implementation guarantees there are no request loops when an invalid
  * password is stored in the login-manager.
  *
  * There is one instance of that object per calendar provider.
  */
 cal.auth.Prompt.prototype = {
+    mProvider: null,
+
     getPasswordInfo: function capGPI(aPasswordRealm) {
         let username;
         let password;
         let found = false;
 
         let logins = Services.logins.findLogins({}, aPasswordRealm.prePath, null, aPasswordRealm.realm);
         if (logins.length) {
             username = logins[0].username;
@@ -242,17 +245,17 @@ cal.auth.Prompt.prototype = {
         let pw = this.getPasswordInfo(hostRealm);
         aAuthInfo.username = pw.username;
         if (pw && pw.found) {
             aAuthInfo.password = pw.password;
             return true;
         } else {
             let prompter2 = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
                                       .getService(Components.interfaces.nsIPromptFactory)
-                                      .getPrompt(null, Components.interfaces.nsIAuthPrompt2);
+                                      .getPrompt(this.mProvider, Components.interfaces.nsIAuthPrompt2);
             return prompter2.promptAuth(aChannel, aLevel, aAuthInfo);
         }
     },
 
     /**
      * Asynchronously prompt the user for a username and password.
      * This has largely the same semantics as promptAuth(),
      * but must return immediately after calling and return the entered
--- a/calendar/base/modules/calProviderUtils.jsm
+++ b/calendar/base/modules/calProviderUtils.jsm
@@ -1,16 +1,17 @@
 /* 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/. */
 
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource://calendar/modules/calUtils.jsm");
 Components.utils.import("resource://calendar/modules/calAuthUtils.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 /*
  * Provider helper code
  */
 
 EXPORTED_SYMBOLS = ["cal"]; // even though it's defined in calUtils.jsm, import needs this
 
 /**
@@ -110,27 +111,29 @@ cal.InterfaceRequestor_getInterface = fu
     try {
         // Try to query the this object for the requested interface but don't
         // throw if it fails since that borks the network code.
         return this.QueryInterface(aIID);
     } catch (e) {
         // Support Auth Prompt Interfaces
         if (aIID.equals(Components.interfaces.nsIAuthPrompt2)) {
             if (!this.calAuthPrompt) {
-                this.calAuthPrompt = new cal.auth.Prompt();
+                this.calAuthPrompt = new cal.auth.Prompt(this);
             }
             return this.calAuthPrompt;
         } else if (aIID.equals(Components.interfaces.nsIAuthPromptProvider) ||
                    aIID.equals(Components.interfaces.nsIPrompt)) {
             return Services.ww.getNewPrompter(null);
         } else if (aIID.equals(Components.interfaces.nsIBadCertListener2)) {
             if (!this.badCertHandler) {
                 this.badCertHandler = new cal.BadCertHandler(this);
             }
             return this.badCertHandler;
+        } else if (aIID.equals(Components.interfaces.nsIWebNavigation)) {
+            return new cal.LoadContext();
         } else {
             Components.returnCode = e;
         }
     }
     return null;
 };
 
 /**
@@ -181,16 +184,35 @@ cal.BadCertHandler.prototype = {
         timer.initWithCallback(timerCallback,
                                0,
                                Components.interfaces.nsITimer.TYPE_ONE_SHOT);
         return true;
     }
 };
 
 /**
+ * Implements an nsILoadContext that allows auth prompts to avoid using private
+ * browsing without a parent DOM window
+ */
+cal.LoadContext = function calLoadContext() {
+};
+cal.LoadContext.prototype = {
+    QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsISupports,
+                                           Components.interfaces.nsILoadContext]),
+    associatedWindow: null,
+    topWindow: null,
+    topFrameElement: null,
+    isAppOfType: function() false,
+    isContent: false,
+    usePrivateBrowsing: false,
+    isInBrowserElement: false,
+    appId: null
+};
+
+/**
  * Freebusy interval implementation. All parameters are optional.
  *
  * @param aCalId         The calendar id to set up with.
  * @param aFreeBusyType  The type from calIFreeBusyInterval.
  * @param aStart         The start of the interval.
  * @param aEnd           The end of the interval.
  * @return               The fresh calIFreeBusyInterval.
  */