diff --git a/browser/extensions/onboarding/bootstrap.js b/browser/extensions/onboarding/bootstrap.js
index cabf6b855848..5d47b0b8ef4b 100644
--- a/browser/extensions/onboarding/bootstrap.js
+++ b/browser/extensions/onboarding/bootstrap.js
@@ -59,6 +59,68 @@ function setPrefs(prefs) {
});
}
+/**
+ * syncTourChecker listens to and maintains the login status inside, and can be
+ * queried at any time once initialized.
+ */
+let syncTourChecker = {
+ _registered: false,
+ _loggedIn: false,
+
+ isLoggedIn() {
+ return this._loggedIn;
+ },
+
+ observe(subject, topic) {
+ switch (topic) {
+ case "fxaccounts:onlogin":
+ this.setComplete();
+ break;
+ case "fxaccounts:onlogout":
+ this._loggedIn = false;
+ break;
+ }
+ },
+
+ init() {
+ // Check if we've already logged in at startup.
+ fxAccounts.getSignedInUser().then(user => {
+ if (user) {
+ this.setComplete();
+ }
+ // Observe for login action if we haven't logged in yet.
+ this.register();
+ });
+ },
+
+ register() {
+ if (this._registered) {
+ return;
+ }
+ Services.obs.addObserver(this, "fxaccounts:onlogin");
+ Services.obs.addObserver(this, "fxaccounts:onlogout");
+ this._registered = true;
+ },
+
+ setComplete() {
+ this._loggedIn = true;
+ Services.prefs.setBoolPref("browser.onboarding.tour.onboarding-tour-sync.completed", true);
+ },
+
+ unregister() {
+ if (!this._registered) {
+ return;
+ }
+ Services.obs.removeObserver(this, "fxaccounts:onlogin");
+ Services.obs.removeObserver(this, "fxaccounts:onlogout");
+ this._registered = false;
+ },
+
+ uninit() {
+ this.unregister();
+ },
+}
+
/**
* Listen and process events from content.
*/
@@ -68,58 +130,15 @@ function initContentMessageListener() {
case "set-prefs":
setPrefs(msg.data.params);
break;
+ case "get-login-status":
+ msg.target.messageManager.sendAsyncMessage("Onboarding:ResponseLoginStatus", {
+ isLoggedIn: syncTourChecker.isLoggedIn()
+ });
+ break;
}
});
}
-let syncTourChecker = {
- registered: false,
-
- observe() {
- this.setComplete();
- },
-
- init() {
- if (Services.prefs.getBoolPref("browser.onboarding.tour.onboarding-tour-sync.completed", false)) {
- return;
- }
- // Check if we've already logged in at startup.
- fxAccounts.getSignedInUser().then(user => {
- if (user) {
- this.setComplete();
- return;
- }
- // Observe for login action if we haven't logged in yet.
- this.register();
- });
- },
-
- register() {
- if (this.registered) {
- return;
- }
- Services.obs.addObserver(this, "fxaccounts:onverified");
- this.registered = true;
- },
-
- setComplete() {
- Services.prefs.setBoolPref("browser.onboarding.tour.onboarding-tour-sync.completed", true);
- this.unregister();
- },
-
- unregister() {
- if (!this.registered) {
- return;
- }
- Services.obs.removeObserver(this, "fxaccounts:onverified");
- this.registered = false;
- },
-
- uninit() {
- this.unregister();
- },
-}
-
/**
* onBrowserReady - Continues startup of the add-on after browser is ready.
*/
diff --git a/browser/extensions/onboarding/content/onboarding.css b/browser/extensions/onboarding/content/onboarding.css
index daa3fd3d97d4..f5c9b46d6d8a 100644
--- a/browser/extensions/onboarding/content/onboarding.css
+++ b/browser/extensions/onboarding/content/onboarding.css
@@ -61,7 +61,9 @@
}
#onboarding-overlay-dialog,
-.onboarding-hidden {
+.onboarding-hidden,
+#onboarding-tour-sync-page[data-login-state=logged-in] .show-on-logged-out,
+#onboarding-tour-sync-page[data-login-state=logged-out] .show-on-logged-in {
display: none;
}
diff --git a/browser/extensions/onboarding/content/onboarding.js b/browser/extensions/onboarding/content/onboarding.js
index f202d148ada2..a7c1eef164d1 100644
--- a/browser/extensions/onboarding/content/onboarding.js
+++ b/browser/extensions/onboarding/content/onboarding.js
@@ -194,8 +194,11 @@ var onboardingTourset = {
};
},
getPage(win, bundle) {
+ const STATE_LOGOUT = "logged-out";
+ const STATE_LOGIN = "logged-in";
let div = win.document.createElement("div");
div.classList.add("onboarding-no-button");
+ div.dataset.loginState = STATE_LOGOUT;
// The email validation pattern used in the form comes from IETF rfc5321,
// which is identical to server-side checker of Firefox Account. See
// discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1378770#c6
@@ -203,11 +206,13 @@ var onboardingTourset = {
let emailRegex = "^[\\w.!#$%&’*+\\/=?^`{|}~-]{1,64}@[a-z\\d](?:[a-z\\d-]{0,253}[a-z\\d])?(?:\\.[a-z\\d](?:[a-z\\d-]{0,253}[a-z\\d])?)+$";
div.innerHTML = `