Bug 1390816 - Part 1: Add addresses sync checkbox in first time saving doorhanger. r=lchang
MozReview-Commit-ID: KkpseMw4kRk
--- a/browser/extensions/formautofill/FormAutofillDoorhanger.jsm
+++ b/browser/extensions/formautofill/FormAutofillDoorhanger.jsm
@@ -44,16 +44,31 @@ const CONTENT = {
mainAction: {
label: GetStringFromName(changeAutofillOptsKey),
accessKey: "C",
callbackState: "open-pref",
},
options: {
persistWhileVisible: true,
popupIconURL: "chrome://formautofill/content/icon-address-save.svg",
+ checkbox: {
+ get checked() {
+ return Services.prefs.getBoolPref("services.sync.engine.addresses");
+ },
+ get label() {
+ // If sync account is not set, return null label to hide checkbox
+ return Services.prefs.prefHasUserValue("services.sync.username") ?
+ GetStringFromName("addressesSyncCheckbox") : null;
+ },
+ callback(event) {
+ let checked = event.target.checked;
+ Services.prefs.setBoolPref("services.sync.engine.addresses", checked);
+ log.debug("Set addresses sync to", checked);
+ },
+ },
},
},
update: {
notificationId: "autofill-address",
message: GetStringFromName("updateAddressMessage"),
anchor: {
id: "autofill-address-notification-icon",
URL: "chrome://formautofill/content/formfill-anchor.svg",
@@ -163,16 +178,42 @@ let FormAutofillDoorhanger = {
anchorElement.id = id;
anchorElement.setAttribute("src", URL);
anchorElement.classList.add("notification-anchor-icon");
anchorElement.setAttribute("role", "button");
anchorElement.setAttribute("tooltiptext", tooltiptext);
notificationPopupBox.appendChild(anchorElement);
}
},
+ _addCheckboxListener(browser, {notificationId, options}) {
+ if (!options.checkbox) {
+ return;
+ }
+ let id = notificationId + "-notification";
+ let chromeDoc = browser.ownerDocument;
+ let notification = chromeDoc.getElementById(id);
+ let cb = notification.checkbox;
+
+ if (cb) {
+ cb.addEventListener("command", options.checkbox.callback);
+ }
+ },
+ _removeCheckboxListener(browser, {notificationId, options}) {
+ if (!options.checkbox) {
+ return;
+ }
+ let id = notificationId + "-notification";
+ let chromeDoc = browser.ownerDocument;
+ let notification = chromeDoc.getElementById(id);
+ let cb = notification.checkbox;
+
+ if (cb) {
+ cb.removeEventListener("command", options.checkbox.callback);
+ }
+ },
/**
* Show different types of doorhanger by leveraging PopupNotifications.
* @param {XULElement} browser
* Target browser element for showing doorhanger.
* @param {string} type
* The type of the doorhanger. There will have first time use/update/credit card.
* @returns {Promise}
Resolved with action type when action callback is triggered.
@@ -180,20 +221,26 @@ let FormAutofillDoorhanger = {
async show(browser, type) {
log.debug("show doorhanger with type:", type);
return new Promise((resolve) => {
let content = CONTENT[type];
let chromeWin = browser.ownerGlobal;
content.options.eventCallback = (topic) => {
log.debug("eventCallback:", topic);
+ if (topic == "removed" || topic == "dismissed") {
+ this._removeCheckboxListener(browser, content);
+ return;
+ }
+
// The doorhanger is customizable only when notification box is shown
if (topic != "shown") {
return;
}
+ this._addCheckboxListener(browser, content);
// There's no preferences link or other customization in first time use doorhanger.
if (type == "firstTimeUse") {
return;
}
this._appendPrivacyPanelLink(browser, content.notificationId);
};
--- a/browser/extensions/formautofill/locales/en-US/formautofill.properties
+++ b/browser/extensions/formautofill/locales/en-US/formautofill.properties
@@ -5,16 +5,17 @@
preferenceGroupTitle = Form Autofill
enableAddressAutofill = Autofill addresses
savedAddresses = Saved Addresses…
saveAddressesMessage = Firefox now saves addresses so you can fill out forms faster.
viewAutofillOptionsLink = View Form Autofill Options
changeAutofillOptions = Change Form Autofill Options
viewAutofillOptionsLinkOSX = View Form Autofill Preferences
changeAutofillOptionsOSX = Change Form Autofill Preferences
+addressesSyncCheckbox = Share addresses with synced devices
updateAddressMessage = Would you like to update your address with this new information?
createAddressLabel = Create New Address
updateAddressLabel = Update Address
openAutofillMessagePanel = Open Form Autofill message panel
autocompleteFooterOption = Form Autofill Options
autocompleteFooterOptionShort = More Options
autocompleteFooterOptionOSX = Form Autofill Preferences
autocompleteFooterOptionOSXShort = Preferences