Bug 966342: Tools menu shows "Sync now" to unverified users in some cases, r=markh
authorGavin Sharp <gavin@gavinsharp.com>
Mon, 10 Mar 2014 17:24:07 -0700
changeset 173144 662beba6065324fa8c9dd8f48d0dcb99b2e025b8
parent 173143 00d3279dfeef3159a8f9eab116f0a7795f3645c0
child 173145 bbf22e4ffe07824d46e9734da77a56c2df61cb6f
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmarkh
bugs966342
milestone30.0a1
Bug 966342: Tools menu shows "Sync now" to unverified users in some cases, r=markh Changes include: - have gSyncUI._needsSetup check Weave.Service.identity._signedInUser (if already set) and return true if the user is not verified - make the menuitem hiding/showing code in gSyncUI.updateUI a bit easier to follow
browser/base/content/browser-syncui.js
--- a/browser/base/content/browser-syncui.js
+++ b/browser/base/content/browser-syncui.js
@@ -83,42 +83,74 @@ let gSyncUI = {
 
     // notificationbox will listen to observers from now on.
     Services.obs.removeObserver(this, "weave:notification:added");
   },
 
   _wasDelayed: false,
 
   _needsSetup: function SUI__needsSetup() {
+    // We want to treat "account needs verification" as "needs setup". We don't
+    // know what the user's verified state is until Sync is initialized, though,
+    // and we need to get an answer here synchronously (can't wait for
+    // getSignedInUser). So "reach in" to Weave.Service.identity to get the
+    // answer here, and we'll just have to deal with this not having an answer
+    // before Sync is initialized.
+
+    // Referencing Weave.Service will implicitly initialize sync, and we don't
+    // want to force that - so first check if it is ready.
+    let service = Cc["@mozilla.org/weave/service;1"]
+                  .getService(Components.interfaces.nsISupports)
+                  .wrappedJSObject;
+    if (service.ready && Weave.Service.identity._signedInUser) {
+      // If we have a signed in user already, and that user is not verified,
+      // revert to the "needs setup" state.
+      if (!Weave.Service.identity._signedInUser.verified) {
+        return true;
+      }
+    }
+
     let firstSync = "";
     try {
       firstSync = Services.prefs.getCharPref("services.sync.firstSync");
     } catch (e) { }
+
     return Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED ||
            firstSync == "notReady";
   },
 
   _loginFailed: function () {
-    // Referencing Weave.Service will implicitly initialize sync, and we don't
+    // Referencing Weave.Status will import a bunch of modules, and we don't
     // want to force that - so first check if it is ready.
     let service = Cc["@mozilla.org/weave/service;1"]
                   .getService(Components.interfaces.nsISupports)
                   .wrappedJSObject;
     if (!service.ready) {
       return false;
     }
+
     return Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED;
   },
 
   updateUI: function SUI_updateUI() {
     let needsSetup = this._needsSetup();
     let loginFailed = this._loginFailed();
-    document.getElementById("sync-setup-state").hidden = loginFailed || !needsSetup;
-    document.getElementById("sync-syncnow-state").hidden = loginFailed || needsSetup;
-    document.getElementById("sync-reauth-state").hidden = !loginFailed;
+
+    // Start off with a clean slate
+    document.getElementById("sync-reauth-state").hidden = true;
+    document.getElementById("sync-setup-state").hidden = true;
+    document.getElementById("sync-syncnow-state").hidden = true;
+
+    if (loginFailed) {
+      document.getElementById("sync-reauth-state").hidden = false;
+    } else if (needsSetup) {
+      document.getElementById("sync-setup-state").hidden = false;
+    } else {
+      document.getElementById("sync-syncnow-state").hidden = false;
+    }
 
     if (!gBrowser)
       return;
 
     let syncButton = document.getElementById("sync-button");
     let panelHorizontalButton = document.getElementById("PanelUI-fxa-status");
     [syncButton, panelHorizontalButton].forEach(function(button) {
       if (!button)