Bug 682474 - Lightning hides Thunderbird master password prompt + multiple password prompts. r=MakeMyDay a=philipp
authorPhilipp Kewisch <mozilla@kewis.ch>
Thu, 24 Nov 2016 02:10:03 +0100
changeset 24473 f3570179a368
parent 24472 7614dd8b69a9
child 24474 05d563fd17e9
push id2061
push usermozilla@jorgk.com
push dateTue, 18 Apr 2017 13:15:21 +0000
treeherdercomm-aurora@05d563fd17e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMakeMyDay, philipp
bugs682474
Bug 682474 - Lightning hides Thunderbird master password prompt + multiple password prompts. r=MakeMyDay a=philipp MozReview-Commit-ID: KuiEVV6sHN5
calendar/base/modules/calAuthUtils.jsm
calendar/providers/caldav/calDavCalendar.js
calendar/providers/gdata/modules/gdataSession.jsm
--- a/calendar/base/modules/calAuthUtils.jsm
+++ b/calendar/base/modules/calAuthUtils.jsm
@@ -295,16 +295,20 @@ cal.auth.Prompt.prototype = {
      */
     asyncPromptAuth: function(aChannel,     // nsIChannel
                               aCallback,    // nsIAuthPromptCallback
                               aContext,     // nsISupports
                               aLevel,       // PRUint32
                               aAuthInfo) {  // nsIAuthInformation
         let self = this;
         let promptlistener = {
+            onPromptStartAsync: function(callback) {
+              callback.onAuthResult(this.onPromptStart());
+            },
+
             onPromptStart: function() {
                 res = self.promptAuth(aChannel, aLevel, aAuthInfo);
 
                 if (res) {
                     gAuthCache.setAuthInfo(hostKey, aAuthInfo);
                     this.onPromptAuthAvailable();
                     return true;
                 }
--- a/calendar/providers/caldav/calDavCalendar.js
+++ b/calendar/providers/caldav/calDavCalendar.js
@@ -387,17 +387,17 @@ calDavCalendar.prototype = {
         let origArgs = arguments;
         let self = this;
 
         if (usesGoogleOAuth && (
               !this.oauth.accessToken ||
               this.oauth.tokenExpires - OAUTH_GRACE_TIME < (new Date()).getTime())) {
             // The token has expired, we need to reauthenticate first
             cal.LOG("CalDAV: OAuth token expired or empty, refreshing");
-            this.oauth.connect(authSuccess, aFailureFunc, true, true);
+            this.oauthConnect(authSuccess, aFailureFunc, true);
         } else {
             // Either not Google OAuth, or the token is still valid.
             authSuccess();
         }
     },
 
     //
     // calICalendar interface
@@ -1550,16 +1550,38 @@ calDavCalendar.prototype = {
      * @see calProviderUtils.jsm
      */
     getInterface: cal.InterfaceRequestor_getInterface,
 
     //
     // Helper functions
     //
 
+    oauthConnect: function(authSuccessCb, authFailureCb, aRefresh=false) {
+        // Use the async prompter to avoid multiple master password prompts
+        let promptlistener = {
+            onPromptStartAsync: function(callback) {
+                self.oauth.connect(() => {
+                    authSuccessCb();
+                    callback.onAuthResult(true);
+                }, () => {
+                    authFailureCb();
+                    callback.onAuthResult(false);
+                }, true, aRefresh);
+            },
+
+            onPromptAuthAvailable: authSuccessCb,
+            onPromptCanceled: authFailureCb,
+            onPromptStart: function() {}
+        };
+        let asyncprompter = Components.classes["@mozilla.org/messenger/msgAsyncPrompter;1"]
+                                      .getService(Components.interfaces.nsIMsgAsyncPrompter);
+        asyncprompter.queueAsyncAuthPrompt(self.uri.spec, false, promptlistener);
+    },
+
     /**
      * Sets up any needed prerequisites regarding authentication. This is the
      * beginning of a chain of asynchronous calls. This function will, when
      * done, call the next function related to checking resource type, server
      * capabilties, etc.
      *
      * setupAuthentication                         * You are here
      * checkDavResourceType
@@ -1573,36 +1595,16 @@ calDavCalendar.prototype = {
         function authSuccess() {
             self.checkDavResourceType(aChangeLogListener);
         }
         function authFailed() {
             self.setProperty("disabled", "true");
             self.setProperty("auto-enabled", "true");
             self.completeCheckServerInfo(aChangeLogListener, Components.results.NS_ERROR_FAILURE);
         }
-        function connect() {
-            // Use the async prompter to avoid multiple master password prompts
-            let promptlistener = {
-                onPromptStart: function() {
-                    // Usually this function should be synchronous. The OAuth
-                    // connection itself is asynchronous, but if a master
-                    // password is prompted it will block on that.
-                    this.onPromptAuthAvailable();
-                    return true;
-                },
-
-                onPromptAuthAvailable: function() {
-                    self.oauth.connect(authSuccess, authFailed, true);
-                },
-                onPromptCanceled: authFailed
-            };
-            let asyncprompter = Components.classes["@mozilla.org/messenger/msgAsyncPrompter;1"]
-                                          .getService(Components.interfaces.nsIMsgAsyncPrompter);
-            asyncprompter.queueAsyncAuthPrompt(self.uri.spec, false, promptlistener);
-        }
         if (this.mUri.host == "apidata.googleusercontent.com") {
             if (!this.oauth) {
                 let sessionId = this.id;
                 let pwMgrId = "Google CalDAV v2";
                 let authTitle = cal.calGetString("commonDialogs", "EnterUserPasswordFor2",
                                                  [this.name], "global");
 
                 this.oauth = new OAuth2(OAUTH_BASE_URI, OAUTH_SCOPE,
@@ -1654,17 +1656,17 @@ calDavCalendar.prototype = {
                 // master password prompt will show just the buttons and
                 // possibly hang. If we postpone until the window is loaded,
                 // all is well.
                 setTimeout(function postpone() { // eslint-disable-line func-names
                     let win = cal.getCalendarWindow();
                     if (!win || win.document.readyState != "complete") {
                         setTimeout(postpone, 0);
                     } else {
-                        connect();
+                        self.oauthConnect(authSuccess, authFailed);
                     }
                 }, 0);
             }
         } else {
             authSuccess();
         }
     },
 
--- a/calendar/providers/gdata/modules/gdataSession.jsm
+++ b/calendar/providers/gdata/modules/gdataSession.jsm
@@ -269,28 +269,28 @@ calGoogleSession.prototype = {
                 }
                 deferred.reject(new Components.Exception(error));
             }.bind(this);
 
             let connect = function() {
                 // Use the async prompter to avoid multiple master password prompts
                 let self = this;
                 let promptlistener = {
-                    onPromptStart: function() {
-                        // Usually this function should be synchronous. The OAuth
-                        // connection itself is asynchronous, but if a master
-                        // password is prompted it will block on that.
-                        this.onPromptAuthAvailable();
-                        return true;
+                    onPromptStartAsync: function(callback) {
+                        self.oauth.connect(() => {
+                            authSuccess();
+                            callback.onAuthResult(true);
+                        }, () => {
+                            authFailed();
+                            callback.onAuthResult(false);
+                        }, true);
                     },
-
-                    onPromptAuthAvailable: function() {
-                        self.oauth.connect(authSuccess, authFailed, true, false);
-                    },
-                    onPromptCanceled: authFailed
+                    onPromptAuthAvailable: authSuccess,
+                    onPromptCanceled: authFailed,
+                    onPromptStart: function() {}
                 };
                 let asyncprompter = Components.classes["@mozilla.org/messenger/msgAsyncPrompter;1"]
                                               .getService(Components.interfaces.nsIMsgAsyncPrompter);
                 asyncprompter.queueAsyncAuthPrompt("googleapi://" + this.id, false, promptlistener);
             }.bind(this);
 
             if (accessToken) {
                 deferred.resolve(accessToken);