Fix bug 349641 - Lightning asks for master password again. r=philipp
authorPhilippe Martinak <philippe.martinak@i-carre.net>
Thu, 28 Apr 2011 07:42:00 +0200
changeset 8069 84251abfe297cd79d1f7f908672106fee24ddba4
parent 8068 0a9a8f6999ab5a880eafe90cdb92313799326114
child 8070 32f5a8ec9c3b72be14af33cd5aa524680f6168af
push id84
push userbugzilla@standard8.plus.com
push dateTue, 16 Aug 2011 21:25:04 +0000
treeherdercomm-beta@6970c86be3cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs349641
Fix bug 349641 - Lightning asks for master password again. r=philipp
calendar/base/modules/calAuthUtils.jsm
--- a/calendar/base/modules/calAuthUtils.jsm
+++ b/calendar/base/modules/calAuthUtils.jsm
@@ -314,42 +314,37 @@ cal.auth.Prompt.prototype = {
      *        the caller should fall back to promptUsernameAndPassword().
      */
     asyncPromptAuth : function capAPA(aChannel,   // nsIChannel
                                       aCallback,  // nsIAuthPromptCallback
                                       aContext,   // nsISupports
                                       aLevel,     // PRUint32
                                       aAuthInfo   // nsIAuthInformation
                                 ) {
-        let hostRealm = {};
-        hostRealm.prePath = aChannel.URI.prePath;
-        hostRealm.realm = aAuthInfo.realm;
-        let port = aChannel.URI.port;
-        if (port == -1) {
-            let handler = cal.getIOService().getProtocolHandler(aChannel.URI.scheme)
-                                            .QueryInterface(Components.interfaces.nsIProtocolHandler);
-            port = handler.defaultPort;
-        }
-        hostRealm.passwordRealm = aChannel.URI.host + ":" + port + " (" + aAuthInfo.realm + ")";
+        var self = this;
+        let promptlistener = {
+
+            onPromptStart: function() {
+                res=self.promptAuth(aChannel, aLevel, aAuthInfo);
+
+                if (res) {
+                    this.onPromptAuthAvailable();
+                    return true;
+                }
 
-        let pw = this.getPasswordInfo(hostRealm);
-        aAuthInfo.username = pw.username;
-        if (pw && pw.found) {
-            aAuthInfo.password = pw.password;
-            // We cannot call the callback directly here so call it from a timer
-            let timerCallback = {
-                notify: function(timer) {
-                    aCallback.onAuthAvailable(aContext, aAuthInfo);
-                }
-            };
-            let timer = Components.classes["@mozilla.org/timer;1"]
-                        .createInstance(Components.interfaces.nsITimer);
-            timer.initWithCallback(timerCallback,
-                                   0,
-                                   Components.interfaces.nsITimer.TYPE_ONE_SHOT);
-        } else {
-            let prompter2 = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
-                                      .getService(Components.interfaces.nsIPromptFactory)
-                                      .getPrompt(null, Components.interfaces.nsIAuthPrompt2);
-            prompter2.asyncPromptAuth(aChannel, aCallback, aContext, aLevel, aAuthInfo);
-        }
+                this.onPromptCanceled();
+                return false;
+            },
+
+            onPromptAuthAvailable : function() {
+                aCallback.onAuthAvailable(aContext, aAuthInfo);
+            },
+
+            onPromptCanceled : function() {
+                aCallback.onAuthCancelled(aContext, true);
+            }
+        };
+
+        var asyncprompter = Components.classes["@mozilla.org/messenger/msgAsyncPrompter;1"]
+                                      .getService(Components.interfaces.nsIMsgAsyncPrompter);
+        asyncprompter.queueAsyncAuthPrompt(aChannel.URI.spec, false, promptlistener);
     }
 };