From 9e06d7e77943c5de94a20c663ea7fda4e23f1647 Mon Sep 17 00:00:00 2001 From: Sam Penrose Date: Fri, 6 Jun 2014 10:42:22 -0700 Subject: [PATCH] Bug 1008901 - Fire 'onlogin' when the account is verified. r=jedp --- services/fxaccounts/FxAccounts.jsm | 6 ++++-- services/fxaccounts/FxAccountsCommon.js | 2 ++ services/fxaccounts/FxAccountsManager.jsm | 12 +++++++----- toolkit/identity/FirefoxAccounts.jsm | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/services/fxaccounts/FxAccounts.jsm b/services/fxaccounts/FxAccounts.jsm index 509b33da0a2..2a53c20b57b 100644 --- a/services/fxaccounts/FxAccounts.jsm +++ b/services/fxaccounts/FxAccounts.jsm @@ -758,9 +758,9 @@ FxAccountsInternal.prototype = { ); }, - notifyObservers: function(topic) { + notifyObservers: function(topic, data) { 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? @@ -800,6 +800,8 @@ FxAccountsInternal.prototype = { currentState.whenVerifiedDeferred.resolve(data); delete currentState.whenVerifiedDeferred; } + // Tell FxAccountsManager to clear its cache + this.notifyObservers(ON_FXA_UPDATE_NOTIFICATION, ONVERIFIED_NOTIFICATION); }); } else { log.debug("polling with step = " + this.POLL_STEP); diff --git a/services/fxaccounts/FxAccountsCommon.js b/services/fxaccounts/FxAccountsCommon.js index 665f38b169e..2bef093f361 100644 --- a/services/fxaccounts/FxAccountsCommon.js +++ b/services/fxaccounts/FxAccountsCommon.js @@ -83,6 +83,8 @@ this.POLL_STEP = 1000 * 3; // 3 seconds this.ONLOGIN_NOTIFICATION = "fxaccounts:onlogin"; this.ONVERIFIED_NOTIFICATION = "fxaccounts:onverified"; this.ONLOGOUT_NOTIFICATION = "fxaccounts:onlogout"; +// Internal to services/fxaccounts only +this.ON_FXA_UPDATE_NOTIFICATION = "fxaccounts:update"; // UI Requests. this.UI_REQUEST_SIGN_IN_FLOW = "signInFlow"; diff --git a/services/fxaccounts/FxAccountsManager.jsm b/services/fxaccounts/FxAccountsManager.jsm index b6f8402c857..2876f76a7ba 100644 --- a/services/fxaccounts/FxAccountsManager.jsm +++ b/services/fxaccounts/FxAccountsManager.jsm @@ -25,15 +25,17 @@ this.FxAccountsManager = { init: function() { Services.obs.addObserver(this, ONLOGOUT_NOTIFICATION, false); + Services.obs.addObserver(this, ON_FXA_UPDATE_NOTIFICATION, false); }, observe: function(aSubject, aTopic, aData) { - if (aTopic !== ONLOGOUT_NOTIFICATION) { - return; - } - - // Remove the cached session if we get a logout notification. + // Both topics indicate our cache is invalid 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 diff --git a/toolkit/identity/FirefoxAccounts.jsm b/toolkit/identity/FirefoxAccounts.jsm index 669f8e47cdb..145fbbaccd4 100644 --- a/toolkit/identity/FirefoxAccounts.jsm +++ b/toolkit/identity/FirefoxAccounts.jsm @@ -39,13 +39,18 @@ log.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter())); XPCOMUtils.defineLazyModuleGetter(this, "FxAccountsManager", "resource://gre/modules/FxAccountsManager.jsm", "FxAccountsManager"); +Cu.import("resource://gre/modules/FxAccountsCommon.js"); #else log.warn("The FxAccountsManager is only functional in B2G at this time."); var FxAccountsManager = null; +var ONVERIFIED_NOTIFICATION = null; #endif function FxAccountsService() { 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 this.RP = this; @@ -61,8 +66,20 @@ FxAccountsService.prototype = { observe: function observe(aSubject, aTopic, aData) { 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": Services.obs.removeObserver(this, "quit-application-granted"); + if (ONVERIFIED_NOTIFICATION) { + Services.obs.removeObserver(this, ONVERIFIED_NOTIFICATION); + } break; } },