From 75afa10dbbb8125494bd60f9c20362e02a225fbd Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Tue, 28 Jan 2014 17:51:09 -0800 Subject: [PATCH] Bug 957426 - Update Sync Options for Firefox Accounts. r=rnewman --- browser/components/preferences/sync.js | 131 +++++++++++++++-- browser/components/preferences/sync.xul | 133 ++++++++++++++++++ .../preferences/preferences.properties | 6 + .../en-US/chrome/browser/preferences/sync.dtd | 20 +++ .../en-US/chrome/browser/syncBrand.dtd | 2 + 5 files changed, 279 insertions(+), 13 deletions(-) diff --git a/browser/components/preferences/sync.js b/browser/components/preferences/sync.js index c4c895a8e596..afc67055e073 100644 --- a/browser/components/preferences/sync.js +++ b/browser/components/preferences/sync.js @@ -8,6 +8,17 @@ Components.utils.import("resource://gre/modules/Services.jsm"); const PAGE_NO_ACCOUNT = 0; const PAGE_HAS_ACCOUNT = 1; const PAGE_NEEDS_UPDATE = 2; +const PAGE_PLEASE_WAIT = 3; +const FXA_PAGE_LOGGED_OUT = 4; +const FXA_PAGE_LOGGED_IN = 5; + +// Indexes into the "login status" deck. +// We are in a successful verified state - everything should work! +const FXA_LOGIN_VERIFIED = 0; +// We have logged in to an unverified account. +const FXA_LOGIN_UNVERIFIED = 1; +// We are logged in locally, but the server rejected our credentials. +const FXA_LOGIN_FAILED = 2; let gSyncPane = { _stringBundle: null, @@ -44,6 +55,10 @@ let gSyncPane = { return; } + // it may take some time before we can determine what provider to use + // and the state of that provider, so show the "please wait" page. + this.page = PAGE_PLEASE_WAIT; + let onUnload = function () { window.removeEventListener("unload", onUnload, false); try { @@ -88,16 +103,59 @@ let gSyncPane = { }, updateWeavePrefs: function () { - if (Weave.Status.service == Weave.CLIENT_NOT_CONFIGURED || - Weave.Svc.Prefs.get("firstSync", "") == "notReady") { + let service = Components.classes["@mozilla.org/weave/service;1"] + .getService(Components.interfaces.nsISupports) + .wrappedJSObject; + // service.fxAccountsEnabled is false iff sync is already configured for + // the legacy provider. + if (service.fxAccountsEnabled) { + // determine the fxa status... + this.page = PAGE_PLEASE_WAIT; + Components.utils.import("resource://gre/modules/FxAccounts.jsm"); + fxAccounts.getSignedInUser().then(data => { + if (!data) { + this.page = FXA_PAGE_LOGGED_OUT; + return; + } + this.page = FXA_PAGE_LOGGED_IN; + // We are logged in locally, but maybe we are in a state where the + // server rejected our credentials (eg, password changed on the server) + let fxaLoginStatus = document.getElementById("fxaLoginStatus"); + let enginesListDisabled; + // Not Verfied implies login error state, so check that first. + if (!data.verified) { + fxaLoginStatus.selectedIndex = FXA_LOGIN_UNVERIFIED; + enginesListDisabled = true; + // So we think we are logged in, so login problems are next. + } else if (Weave.Status.login != Weave.LOGIN_SUCCEEDED) { + fxaLoginStatus.selectedIndex = FXA_LOGIN_FAILED; + enginesListDisabled = true; + // Else we must be golden! + } else { + fxaLoginStatus.selectedIndex = FXA_LOGIN_VERIFIED; + enginesListDisabled = false; + } + document.getElementById("fxaEmailAddress1").textContent = data.email; + document.getElementById("fxaEmailAddress2").textContent = data.email; + document.getElementById("fxaEmailAddress3").textContent = data.email; + document.getElementById("fxaSyncComputerName").value = Weave.Service.clientsEngine.localName; + let enginesList = document.getElementById("fxaSyncEnginesList") + enginesList.disabled = enginesListDisabled; + // *sigh* - disabling the draws each item as if it is disabled, + // but doesn't disable the checkboxes. + for (let checkbox of enginesList.querySelectorAll("checkbox")) { + checkbox.disabled = enginesListDisabled; + } + }); + // If fxAccountEnabled is false and we are in a "not configured" state, + // then fxAccounts is probably fully disabled rather than just unconfigured, + // so handle this case. This block can be removed once we remove support + // for fxAccounts being disabled. + } else if (Weave.Status.service == Weave.CLIENT_NOT_CONFIGURED || + Weave.Svc.Prefs.get("firstSync", "") == "notReady") { this.page = PAGE_NO_ACCOUNT; - let service = Components.classes["@mozilla.org/weave/service;1"] - .getService(Components.interfaces.nsISupports) - .wrappedJSObject; - // no concept of "pair" in an fxAccounts world. - if (service.fxAccountsEnabled) { - document.getElementById("pairDevice").hidden = true; - } + // else: sync was previously configured for the legacy provider, so we + // make the "old" panels available. } else if (Weave.Status.login == Weave.LOGIN_FAILED_INVALID_PASSPHRASE || Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED) { this.needsUpdate(); @@ -163,10 +221,7 @@ let gSyncPane = { .wrappedJSObject; if (service.fxAccountsEnabled) { - let win = Services.wm.getMostRecentWindow("navigator:browser"); - win.switchToTabHavingURI("about:accounts", true); - // seeing as we are doing this in a tab we close the prefs dialog. - window.close(); + this.openContentInBrowser("about:accounts"); } else { let win = Services.wm.getMostRecentWindow("Weave:AccountSetup"); if (win) { @@ -179,6 +234,56 @@ let gSyncPane = { } }, + openContentInBrowser: function(url) { + let win = Services.wm.getMostRecentWindow("navigator:browser"); + if (!win) { + // no window to use, so use _openLink to create a new one. We don't + // always use that as it prefers to open a new window rather than use + // an existing one. + gSyncUtils._openLink(url); + return; + } + win.switchToTabHavingURI(url, true); + // seeing as we are doing this in a tab we close the prefs dialog. + window.close(); + }, + + reSignIn: function() { + this.openContentInBrowser("about:accounts"); + }, + + manageFirefoxAccount: function() { + let url = Services.prefs.getCharPref("identity.fxaccounts.settings.uri"); + this.openContentInBrowser(url); + }, + + verifyFirefoxAccount: function() { + Components.utils.import("resource://gre/modules/FxAccounts.jsm"); + fxAccounts.resendVerificationEmail().then(() => { + fxAccounts.getSignedInUser().then(data => { + let sb = this._stringBundle; + let title = sb.GetStringFromName("firefoxAccountsVerificationSentTitle"); + let heading = sb.formatStringFromName("firefoxAccountsVerificationSentHeading", + [data.email], 1); + let description = sb.GetStringFromName("firefoxAccountVerificationSentDescription"); + + Services.prompt.alert(window, title, heading + "\n\n" + description); + }); + }); + }, + + openOldSyncSupportPage: function() { + let url = Services.urlFormatter.formatURLPref('app.support.baseURL') + "old-sync" + this.openContentInBrowser(url); + }, + + unlinkFirefoxAccount: function(confirm) { + Components.utils.import('resource://gre/modules/FxAccounts.jsm'); + fxAccounts.signOut().then(() => { + this.updateWeavePrefs(); + }); + }, + openQuotaDialog: function () { let win = Services.wm.getMostRecentWindow("Sync:ViewQuota"); if (win) { diff --git a/browser/components/preferences/sync.xul b/browser/components/preferences/sync.xul index 1b3d537c42fe..95dfd143f567 100644 --- a/browser/components/preferences/sync.xul +++ b/browser/components/preferences/sync.xul @@ -38,6 +38,8 @@ + + @@ -175,6 +177,137 @@ onclick="gSyncPane.startOver(true); return false;" value="&unlinkDevice.label;"/> + + + + +

&determiningStatus.label;

+ +
+ + + &welcome.description; + + + + + + + + + + +