mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-29 20:07:30 +09:00
Bug 1176399 - Multiple requests for master password when GMail OAuth2 is enabled.
This commit is contained in:
parent
4103320dde
commit
f7a24c87f6
6 changed files with 101 additions and 21 deletions
|
|
@ -35,20 +35,36 @@ interface nsIMsgAsyncPrompter : nsISupports {
|
||||||
in nsIMsgAsyncPromptListener aCaller);
|
in nsIMsgAsyncPromptListener aCaller);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
[scriptable, function, uuid(acca94c9-378e-46e3-9a91-6655bf9c91a3)]
|
||||||
|
interface nsIMsgAsyncPromptCallback : nsISupports {
|
||||||
|
/**
|
||||||
|
* Called when an auth result is available. Can be passed as a function.
|
||||||
|
*
|
||||||
|
* @param aResult True if there is auth information available following the
|
||||||
|
* prompt, false otherwise.
|
||||||
|
*/
|
||||||
|
void onAuthResult(in boolean aResult);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used in combination with nsIMsgAsyncPrompter.
|
* This is used in combination with nsIMsgAsyncPrompter.
|
||||||
*/
|
*/
|
||||||
[scriptable, uuid(fb5307a3-39d0-462e-92c8-c5c288a2612f)]
|
[scriptable, uuid(fb5307a3-39d0-462e-92c8-c5c288a2612f)]
|
||||||
interface nsIMsgAsyncPromptListener : nsISupports {
|
interface nsIMsgAsyncPromptListener : nsISupports {
|
||||||
/**
|
/**
|
||||||
* Called when the listener should do its prompt. The listener
|
* This method has been deprecated, please use onPromptStartAsync instead.
|
||||||
* should not return until the prompt is complete.
|
|
||||||
*
|
|
||||||
* @return True if there is auth information available following the prompt,
|
|
||||||
* false otherwise.
|
|
||||||
*/
|
*/
|
||||||
boolean onPromptStart();
|
boolean onPromptStart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the listener should do its prompt. This can happen
|
||||||
|
* synchronously or asynchronously, but in any case when done the callback
|
||||||
|
* method should be called.
|
||||||
|
*
|
||||||
|
* @param aCallback The callback to execute when auth prompt has completed.
|
||||||
|
*/
|
||||||
|
void onPromptStartAsync(in nsIMsgAsyncPromptCallback aCallback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called in the case that the queued prompt was combined with another and
|
* Called in the case that the queued prompt was combined with another and
|
||||||
* there is now authentication information available.
|
* there is now authentication information available.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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/Services.jsm");
|
||||||
Components.utils.import("resource://gre/modules/Task.jsm");
|
Components.utils.import("resource://gre/modules/Task.jsm");
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
@ -19,28 +20,46 @@ runnablePrompter.prototype = {
|
||||||
_asyncPrompter: null,
|
_asyncPrompter: null,
|
||||||
_hashKey: 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 *() {
|
run: Task.async(function *() {
|
||||||
yield Services.logins.initializationPromise;
|
yield Services.logins.initializationPromise;
|
||||||
this._asyncPrompter._log.debug("Running prompt for " + this._hashKey);
|
this._asyncPrompter._log.debug("Running prompt for " + this._hashKey);
|
||||||
let prompter = this._asyncPrompter._pendingPrompts[this._hashKey];
|
let prompter = this._asyncPrompter._pendingPrompts[this._hashKey];
|
||||||
let ok = false;
|
let ok = false;
|
||||||
try {
|
try {
|
||||||
ok = prompter.first.onPromptStart();
|
ok = yield this._promiseAuthPrompt(prompter.first);
|
||||||
}
|
} catch (ex) {
|
||||||
catch (ex) {
|
|
||||||
Components.utils.reportError("runnablePrompter:run: " + ex + "\n");
|
Components.utils.reportError("runnablePrompter:run: " + ex + "\n");
|
||||||
|
prompter.first.onPromptCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete this._asyncPrompter._pendingPrompts[this._hashKey];
|
delete this._asyncPrompter._pendingPrompts[this._hashKey];
|
||||||
|
|
||||||
for (var consumer of prompter.consumers) {
|
for (var consumer of prompter.consumers) {
|
||||||
try {
|
try {
|
||||||
if (ok)
|
if (ok) {
|
||||||
consumer.onPromptAuthAvailable();
|
consumer.onPromptAuthAvailable();
|
||||||
else
|
} else {
|
||||||
consumer.onPromptCanceled();
|
consumer.onPromptCanceled();
|
||||||
}
|
}
|
||||||
catch (ex) {
|
} catch (ex) {
|
||||||
// Log the error for extension devs and others to pick up.
|
// Log the error for extension devs and others to pick up.
|
||||||
Components.utils.reportError("runnablePrompter:run: consumer.onPrompt* reported an exception: " + ex + "\n");
|
Components.utils.reportError("runnablePrompter:run: consumer.onPrompt* reported an exception: " + ex + "\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,19 +126,43 @@ OAuth2Module.prototype = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, we need a new login, so create one and fill it in.
|
// 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"]
|
let login = Cc["@mozilla.org/login-manager/loginInfo;1"]
|
||||||
.createInstance(Ci.nsILoginInfo);
|
.createInstance(Ci.nsILoginInfo);
|
||||||
login.init(this._loginUrl, null, this._scope, this._username, token,
|
login.init(this._loginUrl, null, this._scope, this._username, token,
|
||||||
'', '');
|
'', '');
|
||||||
loginMgr.addLogin(login);
|
loginMgr.addLogin(login);
|
||||||
|
}
|
||||||
return token;
|
return token;
|
||||||
},
|
},
|
||||||
|
|
||||||
connect(aWithUI, aListener) {
|
connect(aWithUI, aListener) {
|
||||||
this._oauth.connect(() => aListener.onSuccess(this._oauth.accessToken),
|
let oauth = this._oauth;
|
||||||
x => aListener.onFailure(x),
|
let promptlistener = {
|
||||||
aWithUI, false);
|
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() {
|
buildXOAuth2String() {
|
||||||
|
|
|
||||||
|
|
@ -8513,6 +8513,13 @@ nsresult nsImapProtocol::GetPassword(nsCString &password,
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsImapProtocol::OnPromptStartAsync(nsIMsgAsyncPromptCallback *aCallback)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
OnPromptStart(&result);
|
||||||
|
return aCallback->OnAuthResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
// This is called from the UI thread.
|
// This is called from the UI thread.
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsImapProtocol::OnPromptStart(bool *aResult)
|
nsImapProtocol::OnPromptStart(bool *aResult)
|
||||||
|
|
|
||||||
|
|
@ -740,6 +740,13 @@ nsresult nsPop3Protocol::StartGetAsyncPassword(Pop3StatesEnum aNextState)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsPop3Protocol::OnPromptStartAsync(nsIMsgAsyncPromptCallback *aCallback)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
OnPromptStart(&result);
|
||||||
|
return aCallback->OnAuthResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsPop3Protocol::OnPromptStart(bool *aResult)
|
NS_IMETHODIMP nsPop3Protocol::OnPromptStart(bool *aResult)
|
||||||
{
|
{
|
||||||
MOZ_LOG(POP3LOGMODULE, LogLevel::Debug, (POP3LOG("OnPromptStart()")));
|
MOZ_LOG(POP3LOGMODULE, LogLevel::Debug, (POP3LOG("OnPromptStart()")));
|
||||||
|
|
|
||||||
|
|
@ -2472,6 +2472,13 @@ nsresult nsNNTPProtocol::PasswordResponse()
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsNNTPProtocol::OnPromptStartAsync(nsIMsgAsyncPromptCallback *aCallback)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
OnPromptStart(&result);
|
||||||
|
return aCallback->OnAuthResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP nsNNTPProtocol::OnPromptStart(bool *authAvailable)
|
NS_IMETHODIMP nsNNTPProtocol::OnPromptStart(bool *authAvailable)
|
||||||
{
|
{
|
||||||
NS_ENSURE_ARG_POINTER(authAvailable);
|
NS_ENSURE_ARG_POINTER(authAvailable);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue