Skip to content

Commit

Permalink
Bug 1390816 - Part 1: Add addresses sync checkbox in first time savin…
Browse files Browse the repository at this point in the history
…g doorhanger. r=lchang

MozReview-Commit-ID: KkpseMw4kRk

--HG--
extra : rebase_source : 1dfbacafcedf28bdc2a8a93db35fb5509ff9a889
  • Loading branch information
steveck-chung committed Aug 16, 2017
1 parent d09db9f commit e13ae15
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions browser/extensions/formautofill/FormAutofillDoorhanger.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ const CONTENT = {
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: {
Expand Down Expand Up @@ -168,6 +183,32 @@ let FormAutofillDoorhanger = {
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
Expand All @@ -185,10 +226,16 @@ let FormAutofillDoorhanger = {
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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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
Expand Down

0 comments on commit e13ae15

Please sign in to comment.