summaryrefslogtreecommitdiffstats
path: root/mailnews/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'mailnews/base/src')
-rw-r--r--mailnews/base/src/msgAsyncPrompter.js33
-rw-r--r--mailnews/base/src/msgOAuth2Module.js42
2 files changed, 59 insertions, 16 deletions
diff --git a/mailnews/base/src/msgAsyncPrompter.js b/mailnews/base/src/msgAsyncPrompter.js
index 58b5288e9..ae114683a 100644
--- a/mailnews/base/src/msgAsyncPrompter.js
+++ b/mailnews/base/src/msgAsyncPrompter.js
@@ -2,6 +2,7 @@
* 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://gre/modules/Deprecated.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/Task.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
@@ -19,28 +20,46 @@ runnablePrompter.prototype = {
_asyncPrompter: null,
_hashKey: null,
+ _promiseAuthPrompt: function(listener) {
+ return new Promise((resolve, reject) => {
+ try {
+ listener.onPromptStartAsync({ onAuthResult: resolve });
+ } catch (e) {
+ if (e.result == Components.results.NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED) {
+ // Fall back to onPromptStart, for add-ons compat
+ Deprecated.warning("onPromptStart has been replaced by onPromptStartAsync",
+ "https://bugzilla.mozilla.org/show_bug.cgi?id=1176399");
+ let ok = listener.onPromptStart();
+ resolve(ok);
+ } else {
+ reject(e);
+ }
+ }
+ });
+ },
+
run: Task.async(function *() {
yield Services.logins.initializationPromise;
this._asyncPrompter._log.debug("Running prompt for " + this._hashKey);
let prompter = this._asyncPrompter._pendingPrompts[this._hashKey];
let ok = false;
try {
- ok = prompter.first.onPromptStart();
- }
- catch (ex) {
+ ok = yield this._promiseAuthPrompt(prompter.first);
+ } catch (ex) {
Components.utils.reportError("runnablePrompter:run: " + ex + "\n");
+ prompter.first.onPromptCanceled();
}
delete this._asyncPrompter._pendingPrompts[this._hashKey];
for (var consumer of prompter.consumers) {
try {
- if (ok)
+ if (ok) {
consumer.onPromptAuthAvailable();
- else
+ } else {
consumer.onPromptCanceled();
- }
- catch (ex) {
+ }
+ } catch (ex) {
// Log the error for extension devs and others to pick up.
Components.utils.reportError("runnablePrompter:run: consumer.onPrompt* reported an exception: " + ex + "\n");
}
diff --git a/mailnews/base/src/msgOAuth2Module.js b/mailnews/base/src/msgOAuth2Module.js
index 407ab0519..22d5dc572 100644
--- a/mailnews/base/src/msgOAuth2Module.js
+++ b/mailnews/base/src/msgOAuth2Module.js
@@ -126,19 +126,43 @@ OAuth2Module.prototype = {
}
}
- // Otherwise, we need a new login, so create one and fill it in.
- let login = Cc["@mozilla.org/login-manager/loginInfo;1"]
- .createInstance(Ci.nsILoginInfo);
- login.init(this._loginUrl, null, this._scope, this._username, token,
- '', '');
- loginMgr.addLogin(login);
+ // Unless the token is null, we need to create and fill in a new login
+ if (token) {
+ let login = Cc["@mozilla.org/login-manager/loginInfo;1"]
+ .createInstance(Ci.nsILoginInfo);
+ login.init(this._loginUrl, null, this._scope, this._username, token,
+ '', '');
+ loginMgr.addLogin(login);
+ }
return token;
},
connect(aWithUI, aListener) {
- this._oauth.connect(() => aListener.onSuccess(this._oauth.accessToken),
- x => aListener.onFailure(x),
- aWithUI, false);
+ let oauth = this._oauth;
+ let promptlistener = {
+ onPromptStartAsync: function(callback) {
+ oauth.connect(() => {
+ this.onPromptAuthAvailable();
+ callback.onAuthResult(true);
+ }, (err) => {
+ this.onPromptCanceled();
+ callback.onAuthResult(false);
+ }, aWithUI, false);
+ },
+
+ onPromptAuthAvailable: function() {
+ aListener.onSuccess(oauth.accessToken);
+ },
+ onPromptCanceled: function() {
+ aListener.onFailure(Components.results.NS_ERROR_ABORT);
+ },
+ onPromptStart: function() {}
+ };
+
+ let asyncprompter = Components.classes["@mozilla.org/messenger/msgAsyncPrompter;1"]
+ .getService(Components.interfaces.nsIMsgAsyncPrompter);
+ let promptkey = this._loginUrl + "/" + this._username;
+ asyncprompter.queueAsyncAuthPrompt(promptkey, false, promptlistener);
},
buildXOAuth2String() {