Bug 1008901 - Fire 'onlogin' when the account is verified. r=jedp

This commit is contained in:
Sam Penrose 2014-06-06 10:42:22 -07:00
parent 9aee0d4240
commit 9e06d7e779
4 changed files with 30 additions and 7 deletions

View File

@ -758,9 +758,9 @@ FxAccountsInternal.prototype = {
); );
}, },
notifyObservers: function(topic) { notifyObservers: function(topic, data) {
log.debug("Notifying observers of " + topic); log.debug("Notifying observers of " + topic);
Services.obs.notifyObservers(null, topic, null); Services.obs.notifyObservers(null, topic, data);
}, },
// XXX - pollEmailStatus should maybe be on the AccountState object? // XXX - pollEmailStatus should maybe be on the AccountState object?
@ -800,6 +800,8 @@ FxAccountsInternal.prototype = {
currentState.whenVerifiedDeferred.resolve(data); currentState.whenVerifiedDeferred.resolve(data);
delete currentState.whenVerifiedDeferred; delete currentState.whenVerifiedDeferred;
} }
// Tell FxAccountsManager to clear its cache
this.notifyObservers(ON_FXA_UPDATE_NOTIFICATION, ONVERIFIED_NOTIFICATION);
}); });
} else { } else {
log.debug("polling with step = " + this.POLL_STEP); log.debug("polling with step = " + this.POLL_STEP);

View File

@ -83,6 +83,8 @@ this.POLL_STEP = 1000 * 3; // 3 seconds
this.ONLOGIN_NOTIFICATION = "fxaccounts:onlogin"; this.ONLOGIN_NOTIFICATION = "fxaccounts:onlogin";
this.ONVERIFIED_NOTIFICATION = "fxaccounts:onverified"; this.ONVERIFIED_NOTIFICATION = "fxaccounts:onverified";
this.ONLOGOUT_NOTIFICATION = "fxaccounts:onlogout"; this.ONLOGOUT_NOTIFICATION = "fxaccounts:onlogout";
// Internal to services/fxaccounts only
this.ON_FXA_UPDATE_NOTIFICATION = "fxaccounts:update";
// UI Requests. // UI Requests.
this.UI_REQUEST_SIGN_IN_FLOW = "signInFlow"; this.UI_REQUEST_SIGN_IN_FLOW = "signInFlow";

View File

@ -25,15 +25,17 @@ this.FxAccountsManager = {
init: function() { init: function() {
Services.obs.addObserver(this, ONLOGOUT_NOTIFICATION, false); Services.obs.addObserver(this, ONLOGOUT_NOTIFICATION, false);
Services.obs.addObserver(this, ON_FXA_UPDATE_NOTIFICATION, false);
}, },
observe: function(aSubject, aTopic, aData) { observe: function(aSubject, aTopic, aData) {
if (aTopic !== ONLOGOUT_NOTIFICATION) { // Both topics indicate our cache is invalid
return;
}
// Remove the cached session if we get a logout notification.
this._activeSession = null; this._activeSession = null;
if (aData == ONVERIFIED_NOTIFICATION) {
log.debug("FxAccountsManager: cache cleared, broadcasting: " + aData);
Services.obs.notifyObservers(null, aData, null);
}
}, },
// We don't really need to save fxAccounts instance but this way we allow // We don't really need to save fxAccounts instance but this way we allow

View File

@ -39,13 +39,18 @@ log.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter()));
XPCOMUtils.defineLazyModuleGetter(this, "FxAccountsManager", XPCOMUtils.defineLazyModuleGetter(this, "FxAccountsManager",
"resource://gre/modules/FxAccountsManager.jsm", "resource://gre/modules/FxAccountsManager.jsm",
"FxAccountsManager"); "FxAccountsManager");
Cu.import("resource://gre/modules/FxAccountsCommon.js");
#else #else
log.warn("The FxAccountsManager is only functional in B2G at this time."); log.warn("The FxAccountsManager is only functional in B2G at this time.");
var FxAccountsManager = null; var FxAccountsManager = null;
var ONVERIFIED_NOTIFICATION = null;
#endif #endif
function FxAccountsService() { function FxAccountsService() {
Services.obs.addObserver(this, "quit-application-granted", false); Services.obs.addObserver(this, "quit-application-granted", false);
if (ONVERIFIED_NOTIFICATION) {
Services.obs.addObserver(this, ONVERIFIED_NOTIFICATION, false);
}
// Maintain interface parity with Identity.jsm and MinimalIdentity.jsm // Maintain interface parity with Identity.jsm and MinimalIdentity.jsm
this.RP = this; this.RP = this;
@ -61,8 +66,20 @@ FxAccountsService.prototype = {
observe: function observe(aSubject, aTopic, aData) { observe: function observe(aSubject, aTopic, aData) {
switch (aTopic) { switch (aTopic) {
case null:
// Paranoia against matching null ONVERIFIED_NOTIFICATION
break;
case ONVERIFIED_NOTIFICATION:
log.debug("Received " + ONVERIFIED_NOTIFICATION + "; firing request()s");
for (let [rpId,] of this._rpFlows) {
this.request(rpId);
}
break;
case "quit-application-granted": case "quit-application-granted":
Services.obs.removeObserver(this, "quit-application-granted"); Services.obs.removeObserver(this, "quit-application-granted");
if (ONVERIFIED_NOTIFICATION) {
Services.obs.removeObserver(this, ONVERIFIED_NOTIFICATION);
}
break; break;
} }
}, },