mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-01 13:57:32 +00:00
Bug 958927 - XUL dialogs for sync unlink and relink confirmation dialogs. r=gavin
Conflicts: browser/base/content/aboutaccounts/aboutaccounts.js --HG-- extra : rebase_source : 2c81fe29d3b85eb8174b988cbaff516e71c39358
This commit is contained in:
parent
387900638e
commit
b21501e4dc
@ -9,6 +9,8 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/FxAccounts.jsm");
|
||||
|
||||
const PREF_LAST_FXA_USER = "identity.fxaccounts.lastSignedInUser";
|
||||
|
||||
function log(msg) {
|
||||
//dump("FXA: " + msg + "\n");
|
||||
};
|
||||
@ -17,6 +19,44 @@ function error(msg) {
|
||||
console.log("Firefox Account Error: " + msg + "\n");
|
||||
};
|
||||
|
||||
function getPreviousAccountName() {
|
||||
try {
|
||||
return Services.prefs.getComplexValue(PREF_LAST_FXA_USER, Ci.nsISupportsString).data;
|
||||
} catch (_) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function setPreviousAccountName(acctName) {
|
||||
let string = Cc["@mozilla.org/supports-string;1"]
|
||||
.createInstance(Ci.nsISupportsString);
|
||||
string.data = acctName;
|
||||
Services.prefs.setComplexValue(PREF_LAST_FXA_USER, Ci.nsISupportsString, string);
|
||||
}
|
||||
|
||||
function needRelinkWarning(accountData) {
|
||||
let prevAcct = getPreviousAccountName();
|
||||
return prevAcct && prevAcct != accountData.email;
|
||||
}
|
||||
|
||||
function promptForRelink() {
|
||||
let sb = Services.strings.createBundle("chrome://browser/locale/syncSetup.properties");
|
||||
let continueLabel = sb.GetStringFromName("continue.label");
|
||||
let title = sb.GetStringFromName("relink.verify.title");
|
||||
let description = sb.formatStringFromName("relink.verify.description",
|
||||
[Services.prefs.getCharPref(PREF_LAST_FXA_USER)], 1);
|
||||
let body = sb.GetStringFromName("relink.verify.heading") +
|
||||
"\n\n" + description;
|
||||
let ps = Services.prompt;
|
||||
let buttonFlags = (ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING) +
|
||||
(ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL) +
|
||||
ps.BUTTON_POS_1_DEFAULT;
|
||||
let pressed = Services.prompt.confirmEx(window, title, body, buttonFlags,
|
||||
continueLabel, null, null, null,
|
||||
{});
|
||||
return pressed == 0; // 0 is the "continue" button
|
||||
}
|
||||
|
||||
let wrapper = {
|
||||
iframe: null,
|
||||
|
||||
@ -68,6 +108,23 @@ let wrapper = {
|
||||
delete accountData.customizeSync;
|
||||
}
|
||||
|
||||
// If the last fxa account used for sync isn't this account, we display
|
||||
// a modal dialog checking they really really want to do this...
|
||||
// (This is sync-specific, so ideally would be in sync's identity module,
|
||||
// but it's a little more seamless to do here, and sync is currently the
|
||||
// only fxa consumer, so...
|
||||
if (needRelinkWarning(accountData) && !promptForRelink()) {
|
||||
// we need to tell the page we successfully received the message, but
|
||||
// then bail without telling fxAccounts
|
||||
this.injectData("message", { status: "login" });
|
||||
// and reload the page or else it remains in a "signed in" state.
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// Remember who it was so we can log out next time.
|
||||
setPreviousAccountName(accountData.email);
|
||||
|
||||
fxAccounts.setSignedInUser(accountData).then(
|
||||
() => {
|
||||
this.injectData("message", { status: "login" });
|
||||
|
@ -278,6 +278,25 @@ let gSyncPane = {
|
||||
},
|
||||
|
||||
unlinkFirefoxAccount: function(confirm) {
|
||||
if (confirm) {
|
||||
// We use a string bundle shared with aboutAccounts.
|
||||
let sb = Services.strings.createBundle("chrome://browser/locale/syncSetup.properties");
|
||||
let continueLabel = sb.GetStringFromName("continue.label");
|
||||
let title = sb.GetStringFromName("unlink.verify.title");
|
||||
let body = sb.GetStringFromName("unlink.verify.heading") +
|
||||
"\n\n" +
|
||||
sb.GetStringFromName("unlink.verify.description");
|
||||
let ps = Services.prompt;
|
||||
let buttonFlags = (ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING) +
|
||||
(ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL) +
|
||||
ps.BUTTON_POS_1_DEFAULT;
|
||||
let pressed = Services.prompt.confirmEx(window, title, body, buttonFlags,
|
||||
continueLabel, null, null, null,
|
||||
{});
|
||||
if (pressed != 0) { // 0 is the "continue" button
|
||||
return;
|
||||
}
|
||||
}
|
||||
Components.utils.import('resource://gre/modules/FxAccounts.jsm');
|
||||
fxAccounts.signOut().then(() => {
|
||||
this.updateWeavePrefs();
|
||||
|
@ -49,3 +49,14 @@ existingAccount.change.label = You can change this preference by selecting Sync
|
||||
|
||||
# Several other strings are used (via Weave.Status.login), but they come from
|
||||
# /services/sync
|
||||
|
||||
# Firefox Accounts based setup.
|
||||
continue.label = Continue
|
||||
unlink.verify.title = Unlink Browser
|
||||
unlink.verify.heading = Are you sure?
|
||||
unlink.verify.description = This browser will stop syncing with your other computers, but won't delete any of your local browsing data.
|
||||
|
||||
relink.verify.title = Merge Warning
|
||||
relink.verify.heading = Are you sure you want to sign in to Sync?
|
||||
# LOCALIZATION NOTE (relink.verify.description): Email address of a user previously signed into sync.
|
||||
relink.verify.description = A different user was previously signed in to Sync on this device. Signing in will merge this browser's bookmarks, passwords and other settings with %S
|
||||
|
Loading…
x
Reference in New Issue
Block a user