Bug 901329 - Thunderbird doesn't start when using master password and Google CalDAV OAuth2 authentication. r=mmecca
This commit is contained in:
Родитель
e88bf08c91
Коммит
55920f7b6b
|
@ -88,8 +88,12 @@ OAuth2.prototype = {
|
|||
_active: true,
|
||||
iconURI: "",
|
||||
cancelled: function() {
|
||||
if (!this._active)
|
||||
if (!this._active) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.account.finishAuthorizationRequest();
|
||||
this.account.onAuthorizationFailed();
|
||||
},
|
||||
|
||||
loaded: function (aWindow, aWebProgress) {
|
||||
|
@ -150,12 +154,18 @@ OAuth2.prototype = {
|
|||
this._browserRequest._listener._cleanUp();
|
||||
delete this._browserRequest;
|
||||
},
|
||||
|
||||
onAuthorizationReceived: function(aData) {
|
||||
this.log.info("authorization received" + aData);
|
||||
let results = parseURLData(aData);
|
||||
this.requestAccessToken(results.code, OAuth2.CODE_AUTHORIZATION);
|
||||
},
|
||||
|
||||
onAuthorizationFailed: function() {
|
||||
this.connecting = false;
|
||||
this.connectFailureCallback();
|
||||
},
|
||||
|
||||
requestAccessToken: function requestAccessToken(aCode, aType) {
|
||||
|
||||
let params = [
|
||||
|
|
|
@ -95,7 +95,9 @@ cal.auth = {
|
|||
Services.logins.addLogin(newLoginInfo);
|
||||
}
|
||||
} catch (exc) {
|
||||
cal.ASSERT(false, exc);
|
||||
// Only show the message if its not an abort, which can happen if
|
||||
// the user canceled the master password dialog
|
||||
cal.ASSERT(exc.result == Components.results.NS_ERROR_ABORT, exc);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
Components.utils.import("resource://gre/modules/Timer.jsm");
|
||||
|
||||
Components.utils.import("resource://calendar/modules/calUtils.jsm");
|
||||
Components.utils.import("resource://calendar/modules/calXMLUtils.jsm");
|
||||
|
@ -1550,6 +1551,26 @@ calDavCalendar.prototype = {
|
|||
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) {
|
||||
this.oauth = new OAuth2(OAUTH_BASE_URI, OAUTH_SCOPE,
|
||||
|
@ -1561,16 +1582,24 @@ calDavCalendar.prototype = {
|
|||
get: function getRefreshToken() {
|
||||
if (!this.mRefreshToken) {
|
||||
var pass = { value: null };
|
||||
cal.auth.passwordManagerGet(sessionId, pass, sessionId, pwMgrId);
|
||||
try {
|
||||
cal.auth.passwordManagerGet(sessionId, pass, sessionId, pwMgrId);
|
||||
} catch (e if e.result == Components.results.NS_ERROR_ABORT) {
|
||||
// User might have cancelled the master password prompt, thats ok
|
||||
}
|
||||
this.mRefreshToken = pass.value;
|
||||
}
|
||||
return this.mRefreshToken;
|
||||
},
|
||||
set: function setRefreshToken(val) {
|
||||
if (!val) {
|
||||
cal.auth.passwordManagerRemove(sessionId, sessionId, pwMgrId);
|
||||
} else {
|
||||
cal.auth.passwordManagerSave(sessionId, val, sessionId, pwMgrId);
|
||||
try {
|
||||
if (!val) {
|
||||
cal.auth.passwordManagerRemove(sessionId, sessionId, pwMgrId);
|
||||
} else {
|
||||
cal.auth.passwordManagerSave(sessionId, val, sessionId, pwMgrId);
|
||||
}
|
||||
} catch (e if e.result == Components.results.NS_ERROR_ABORT) {
|
||||
// User might have cancelled the master password prompt, thats ok
|
||||
}
|
||||
return (this.mRefreshToken = val);
|
||||
},
|
||||
|
@ -1581,7 +1610,20 @@ calDavCalendar.prototype = {
|
|||
if (this.oauth.accessToken) {
|
||||
authSuccess();
|
||||
} else {
|
||||
this.oauth.connect(authSuccess, authFailed, true);
|
||||
// bug 901329: If the calendar window isn't loaded yet the
|
||||
// master password prompt will show just the buttons and
|
||||
// possibly hang. If we postpone until the window is loaded,
|
||||
// all is well.
|
||||
function postpone() {
|
||||
let win = cal.getCalendarWindow();
|
||||
if (!win || win.document.readyState != "complete") {
|
||||
setTimeout(postpone, 0);
|
||||
} else {
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(postpone, 0);
|
||||
}
|
||||
} else {
|
||||
authSuccess();
|
||||
|
|
Загрузка…
Ссылка в новой задаче